Skip to content

Commit d3e2d78

Browse files
committed
Fix for autolinking strings in the form of version:1.0, which were being interpreted as a protocol:domain url
1 parent b447527 commit d3e2d78

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ autolinker.link( "Go to www.google.com" );
148148

149149
## Changelog:
150150

151+
### 0.10.1
152+
153+
- Added fix to not autolink strings like "version:1.0", which were accidentally being interpreted as a protocol:domain string.
154+
151155
### 0.10.0
152156

153157
- Added support for protocol-relative URLs (ex: `//google.com`, which will effectively either have the `http://` or `https://`

dist/Autolinker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* Autolinker.js
3-
* 0.10.0
3+
* 0.10.1
44
*
55
* Copyright(c) 2014 Gregory Jacobs <[email protected]>
66
* MIT Licensed. http://www.opensource.org/licenses/mit-license.php
@@ -381,6 +381,7 @@
381381
if(
382382
( twitterMatch && !enableTwitter ) || ( emailAddress && !enableEmailAddresses ) || ( urlMatch && !enableUrls ) ||
383383
( urlMatch && urlMatch.indexOf( '.' ) === -1 ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL
384+
( urlMatch && /^[A-Za-z]{3,9}:/.test( urlMatch ) && !/:.*?[A-Za-z]/.test( urlMatch ) ) || // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
384385
( protocolRelativeMatch && /^[\w]\/\//.test( protocolRelativeMatch ) ) // a protocol-relative match which has a word character in front of it (so we can skip something like "abc//google.com")
385386
) {
386387
return matchStr;

dist/Autolinker.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "autolinker",
3-
"version": "0.10.0",
3+
"version": "0.10.1",
44
"description": "Simple utility to automatically link the URLs, email addresses, and Twitter handles in a given block of text/HTML",
55
"main": "dist/Autolinker.js",
66
"directories": {

src/Autolinker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@
372372
if(
373373
( twitterMatch && !enableTwitter ) || ( emailAddress && !enableEmailAddresses ) || ( urlMatch && !enableUrls ) ||
374374
( urlMatch && urlMatch.indexOf( '.' ) === -1 ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL
375+
( urlMatch && /^[A-Za-z]{3,9}:/.test( urlMatch ) && !/:.*?[A-Za-z]/.test( urlMatch ) ) || // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
375376
( protocolRelativeMatch && /^[\w]\/\//.test( protocolRelativeMatch ) ) // a protocol-relative match which has a word character in front of it (so we can skip something like "abc//google.com")
376377
) {
377378
return matchStr;

tests/AutolinkerSpec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ describe( "Autolinker", function() {
7878
expect( result ).toBe( 'Something like <a href="git:domain.com">git:domain.com</a> should be linked as a URL' );
7979
} );
8080

81+
82+
it( "should NOT automatically link a string in the form of 'version:1.0'", function() {
83+
var result = autolinker.link( 'version:1.0' );
84+
expect( result ).toBe( 'version:1.0' );
85+
} );
86+
87+
88+
it( "should NOT automatically link these 'abc:def' style strings", function() {
89+
var strings = [
90+
'BEGIN:VCALENDAR',
91+
'VERSION:1.0',
92+
'BEGIN:VEVENT',
93+
'DTSTART:20140401T090000',
94+
'DTEND:20140401T100000',
95+
'SUMMARY:Some thing to do',
96+
'LOCATION:',
97+
'DESCRIPTION:Just call this guy yeah! Testings',
98+
'PRIORITY:3',
99+
'END:VEVENT',
100+
'END:VCALENDAR'
101+
];
102+
103+
for( var i = 0, len = strings.length; i < len; i++ ) {
104+
expect( autolinker.link( strings[ i ] ) ).toBe( strings[ i ] ); // none should be autolinked
105+
}
106+
} );
107+
81108
} );
82109

83110

0 commit comments

Comments
 (0)