Skip to content

Commit 2479a45

Browse files
committed
Match URI scheme names that are greater than 9 characters, and allow for digits, +, ., and - in the scheme name. (Ex: 'chrome-extension:')
1 parent 55e4122 commit 2479a45

File tree

7 files changed

+274
-104
lines changed

7 files changed

+274
-104
lines changed

dist/Autolinker.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/*!
1818
* Autolinker.js
19-
* 0.13.1
19+
* 0.14.0
2020
*
2121
* Copyright(c) 2014 Gregory Jacobs <[email protected]>
2222
* MIT Licensed. http://www.opensource.org/licenses/mit-license.php
@@ -243,7 +243,7 @@
243243

244244
emailRegex = /(?:[\-;:&=\+\$,\w\.]+@)/, // something@ for email addresses (a.k.a. local-part)
245245

246-
protocolRegex = /(?:[A-Za-z]{3,9}:(?![A-Za-z]{3,9}:\/\/)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:")
246+
protocolRegex = /(?:[A-Za-z][-.+A-Za-z0-9]+:(?![A-Za-z][-.+A-Za-z0-9]+:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex)
247247
wwwRegex = /(?:www\.)/, // starting with 'www.'
248248
domainNameRegex = /[A-Za-z0-9\.\-]*[A-Za-z0-9\-]/, // anything looking at all like a domain, non-unicode domains, not ending in a period
249249
tldRegex = /\.(?:international|construction|contractors|enterprises|photography|productions|foundation|immobilien|industries|management|properties|technology|christmas|community|directory|education|equipment|institute|marketing|solutions|vacations|bargains|boutique|builders|catering|cleaning|clothing|computer|democrat|diamonds|graphics|holdings|lighting|partners|plumbing|supplies|training|ventures|academy|careers|company|cruises|domains|exposed|flights|florist|gallery|guitars|holiday|kitchen|neustar|okinawa|recipes|rentals|reviews|shiksha|singles|support|systems|agency|berlin|camera|center|coffee|condos|dating|estate|events|expert|futbol|kaufen|luxury|maison|monash|museum|nagoya|photos|repair|report|social|supply|tattoo|tienda|travel|viajes|villas|vision|voting|voyage|actor|build|cards|cheap|codes|dance|email|glass|house|mango|ninja|parts|photo|shoes|solar|today|tokyo|tools|watch|works|aero|arpa|asia|best|bike|blue|buzz|camp|club|cool|coop|farm|fish|gift|guru|info|jobs|kiwi|kred|land|limo|link|menu|mobi|moda|name|pics|pink|post|qpon|rich|ruhr|sexy|tips|vote|voto|wang|wien|wiki|zone|bar|bid|biz|cab|cat|ceo|com|edu|gov|int|kim|mil|net|onl|org|pro|pub|red|tel|uno|wed|xxx|xyz|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)\b/, // match our known top level domains (TLDs)
@@ -563,7 +563,8 @@
563563
match = new Autolinker.match.Url( {
564564
matchedText : matchStr,
565565
url : matchStr,
566-
protocolRelativeMatch : protocolRelativeMatch,
566+
protocolUrlMatch : !!protocolUrlMatch,
567+
protocolRelativeMatch : !!protocolRelativeMatch,
567568
stripPrefix : this.stripPrefix
568569
} );
569570
}
@@ -1318,23 +1319,23 @@
13181319
* @private
13191320
* @property {RegExp} hasFullProtocolRegex
13201321
*/
1321-
hasFullProtocolRegex : /^[A-Za-z]{3,9}:\/\//,
1322+
hasFullProtocolRegex : /^[A-Za-z][-.+A-Za-z0-9]+:\/\//,
13221323

13231324
/**
13241325
* Regex to test for a protocol prefix, such as 'mailto:'
13251326
*
13261327
* @private
13271328
* @property {RegExp} hasProtocolPrefixRegex
13281329
*/
1329-
hasProtocolPrefixRegex : /^[A-Za-z]{3,9}:/,
1330+
hasProtocolPrefixRegex : /^[A-Za-z][-.+A-Za-z0-9]+:/,
13301331

13311332
/**
13321333
* Regex to determine if at least one word char exists after the protocol (i.e. after the ':')
13331334
*
13341335
* @private
13351336
* @property {RegExp} hasWordCharAfterProtocolRegex
13361337
*/
1337-
hasWordCharAfterProtocolRegex : /:.*?[A-Za-z]/,
1338+
hasWordCharAfterProtocolRegex : /:[^\s]*?[A-Za-z]/,
13381339

13391340

13401341
/**
@@ -1360,9 +1361,9 @@
13601361
*/
13611362
isValidMatch : function( urlMatch, protocolUrlMatch, protocolRelativeMatch ) {
13621363
if(
1363-
this.urlMatchDoesNotHaveProtocolOrDot( urlMatch, protocolUrlMatch ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost')
1364-
this.urlMatchDoesNotHaveAtLeastOneWordChar( urlMatch ) || // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
1365-
this.isInvalidProtocolRelativeMatch( protocolRelativeMatch ) // A protocol-relative match which has a word character in front of it (so we can skip something like "abc//google.com")
1364+
this.urlMatchDoesNotHaveProtocolOrDot( urlMatch, protocolUrlMatch ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost')
1365+
this.urlMatchDoesNotHaveAtLeastOneWordChar( urlMatch, protocolUrlMatch ) || // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
1366+
this.isInvalidProtocolRelativeMatch( protocolRelativeMatch ) // A protocol-relative match which has a word character in front of it (so we can skip something like "abc//google.com")
13661367
) {
13671368
return false;
13681369
}
@@ -1388,7 +1389,7 @@
13881389
* match.
13891390
*/
13901391
urlMatchDoesNotHaveProtocolOrDot : function( urlMatch, protocolUrlMatch ) {
1391-
return ( urlMatch && ( !protocolUrlMatch || !this.hasFullProtocolRegex.test( protocolUrlMatch ) ) && urlMatch.indexOf( '.' ) === -1 );
1392+
return ( !!urlMatch && ( !protocolUrlMatch || !this.hasFullProtocolRegex.test( protocolUrlMatch ) ) && urlMatch.indexOf( '.' ) === -1 );
13921393
},
13931394

13941395

@@ -1400,11 +1401,18 @@
14001401
*
14011402
* @private
14021403
* @param {String} urlMatch The matched URL, if there was one. Will be an empty string if the match is not a URL match.
1404+
* @param {String} protocolUrlMatch The match URL string for a protocol match. Ex: 'http://yahoo.com'. This is used to
1405+
* know whether or not we have a protocol in the URL string, in order to check for a word character after the protocol
1406+
* separator (':').
14031407
* @return {Boolean} `true` if the URL match does not have at least one word character in it after the protocol, `false`
14041408
* otherwise.
14051409
*/
1406-
urlMatchDoesNotHaveAtLeastOneWordChar : function( urlMatch ) {
1407-
return ( urlMatch && this.hasProtocolPrefixRegex.test( urlMatch ) && !this.hasWordCharAfterProtocolRegex.test( urlMatch ) );
1410+
urlMatchDoesNotHaveAtLeastOneWordChar : function( urlMatch, protocolUrlMatch ) {
1411+
if( urlMatch && protocolUrlMatch ) {
1412+
return !this.hasWordCharAfterProtocolRegex.test( urlMatch );
1413+
} else {
1414+
return false;
1415+
}
14081416
},
14091417

14101418

@@ -1420,7 +1428,7 @@
14201428
* @return {Boolean} `true` if it is an invalid protocol-relative match, `false` otherwise.
14211429
*/
14221430
isInvalidProtocolRelativeMatch : function( protocolRelativeMatch ) {
1423-
return ( protocolRelativeMatch && this.invalidProtocolRelMatchRegex.test( protocolRelativeMatch ) );
1431+
return ( !!protocolRelativeMatch && this.invalidProtocolRelMatchRegex.test( protocolRelativeMatch ) );
14241432
}
14251433

14261434
} );
@@ -1785,6 +1793,13 @@
17851793
* The url that was matched.
17861794
*/
17871795

1796+
/**
1797+
* @cfg {Boolean} protocolUrlMatch (required)
1798+
*
1799+
* `true` if the URL is a match which already has a protocol (i.e. 'http://'), `false` if the match was from a 'www' or
1800+
* known TLD match.
1801+
*/
1802+
17881803
/**
17891804
* @cfg {Boolean} protocolRelativeMatch (required)
17901805
*
@@ -1816,13 +1831,13 @@
18161831
protocolRelativeRegex : /^\/\//,
18171832

18181833
/**
1819-
* @protected
1820-
* @property {RegExp} checkForProtocolRegex
1834+
* @private
1835+
* @property {Boolean} protocolPrepended
18211836
*
1822-
* A regular expression used to check if the {@link #url} is missing a protocol (in which case, 'http://'
1823-
* will be added).
1837+
* Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the
1838+
* {@link #url} did not have a protocol)
18241839
*/
1825-
checkForProtocolRegex: /^[A-Za-z]{3,9}:/,
1840+
protocolPrepended : false,
18261841

18271842

18281843
/**
@@ -1836,17 +1851,19 @@
18361851

18371852

18381853
/**
1839-
* Returns the url that was matched, assuming the protocol to be 'http://' if the match
1840-
* was missing a protocol.
1854+
* Returns the url that was matched, assuming the protocol to be 'http://' if the original
1855+
* match was missing a protocol.
18411856
*
18421857
* @return {String}
18431858
*/
18441859
getUrl : function() {
18451860
var url = this.url;
18461861

1847-
// if the url string doesn't begin with a protocol, assume http://
1848-
if( !this.protocolRelativeMatch && !this.checkForProtocolRegex.test( url ) ) {
1862+
// if the url string doesn't begin with a protocol, assume 'http://'
1863+
if( !this.protocolRelativeMatch && !this.protocolUrlMatch && !this.protocolPrepended ) {
18491864
url = this.url = 'http://' + url;
1865+
1866+
this.protocolPrepended = true;
18501867
}
18511868

18521869
return url;

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.13.1",
3+
"version": "0.14.0",
44
"description": "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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Autolinker.prototype = {
218218

219219
emailRegex = /(?:[\-;:&=\+\$,\w\.]+@)/, // something@ for email addresses (a.k.a. local-part)
220220

221-
protocolRegex = /(?:[A-Za-z]{3,9}:(?![A-Za-z]{3,9}:\/\/)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:")
221+
protocolRegex = /(?:[A-Za-z][-.+A-Za-z0-9]+:(?![A-Za-z][-.+A-Za-z0-9]+:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex)
222222
wwwRegex = /(?:www\.)/, // starting with 'www.'
223223
domainNameRegex = /[A-Za-z0-9\.\-]*[A-Za-z0-9\-]/, // anything looking at all like a domain, non-unicode domains, not ending in a period
224224
tldRegex = /\.(?:international|construction|contractors|enterprises|photography|productions|foundation|immobilien|industries|management|properties|technology|christmas|community|directory|education|equipment|institute|marketing|solutions|vacations|bargains|boutique|builders|catering|cleaning|clothing|computer|democrat|diamonds|graphics|holdings|lighting|partners|plumbing|supplies|training|ventures|academy|careers|company|cruises|domains|exposed|flights|florist|gallery|guitars|holiday|kitchen|neustar|okinawa|recipes|rentals|reviews|shiksha|singles|support|systems|agency|berlin|camera|center|coffee|condos|dating|estate|events|expert|futbol|kaufen|luxury|maison|monash|museum|nagoya|photos|repair|report|social|supply|tattoo|tienda|travel|viajes|villas|vision|voting|voyage|actor|build|cards|cheap|codes|dance|email|glass|house|mango|ninja|parts|photo|shoes|solar|today|tokyo|tools|watch|works|aero|arpa|asia|best|bike|blue|buzz|camp|club|cool|coop|farm|fish|gift|guru|info|jobs|kiwi|kred|land|limo|link|menu|mobi|moda|name|pics|pink|post|qpon|rich|ruhr|sexy|tips|vote|voto|wang|wien|wiki|zone|bar|bid|biz|cab|cat|ceo|com|edu|gov|int|kim|mil|net|onl|org|pro|pub|red|tel|uno|wed|xxx|xyz|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)\b/, // match our known top level domains (TLDs)
@@ -538,7 +538,8 @@ Autolinker.prototype = {
538538
match = new Autolinker.match.Url( {
539539
matchedText : matchStr,
540540
url : matchStr,
541-
protocolRelativeMatch : protocolRelativeMatch,
541+
protocolUrlMatch : !!protocolUrlMatch,
542+
protocolRelativeMatch : !!protocolRelativeMatch,
542543
stripPrefix : this.stripPrefix
543544
} );
544545
}

src/MatchValidator.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ Autolinker.MatchValidator = Autolinker.Util.extend( Object, {
3434
* @private
3535
* @property {RegExp} hasFullProtocolRegex
3636
*/
37-
hasFullProtocolRegex : /^[A-Za-z]{3,9}:\/\//,
37+
hasFullProtocolRegex : /^[A-Za-z][-.+A-Za-z0-9]+:\/\//,
3838

3939
/**
4040
* Regex to test for a protocol prefix, such as 'mailto:'
4141
*
4242
* @private
4343
* @property {RegExp} hasProtocolPrefixRegex
4444
*/
45-
hasProtocolPrefixRegex : /^[A-Za-z]{3,9}:/,
45+
hasProtocolPrefixRegex : /^[A-Za-z][-.+A-Za-z0-9]+:/,
4646

4747
/**
4848
* Regex to determine if at least one word char exists after the protocol (i.e. after the ':')
4949
*
5050
* @private
5151
* @property {RegExp} hasWordCharAfterProtocolRegex
5252
*/
53-
hasWordCharAfterProtocolRegex : /:.*?[A-Za-z]/,
53+
hasWordCharAfterProtocolRegex : /:[^\s]*?[A-Za-z]/,
5454

5555

5656
/**
@@ -76,9 +76,9 @@ Autolinker.MatchValidator = Autolinker.Util.extend( Object, {
7676
*/
7777
isValidMatch : function( urlMatch, protocolUrlMatch, protocolRelativeMatch ) {
7878
if(
79-
this.urlMatchDoesNotHaveProtocolOrDot( urlMatch, protocolUrlMatch ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost')
80-
this.urlMatchDoesNotHaveAtLeastOneWordChar( urlMatch ) || // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
81-
this.isInvalidProtocolRelativeMatch( protocolRelativeMatch ) // A protocol-relative match which has a word character in front of it (so we can skip something like "abc//google.com")
79+
this.urlMatchDoesNotHaveProtocolOrDot( urlMatch, protocolUrlMatch ) || // At least one period ('.') must exist in the URL match for us to consider it an actual URL, *unless* it was a full protocol match (like 'http://localhost')
80+
this.urlMatchDoesNotHaveAtLeastOneWordChar( urlMatch, protocolUrlMatch ) || // At least one letter character must exist in the domain name after a protocol match. Ex: skip over something like "git:1.0"
81+
this.isInvalidProtocolRelativeMatch( protocolRelativeMatch ) // A protocol-relative match which has a word character in front of it (so we can skip something like "abc//google.com")
8282
) {
8383
return false;
8484
}
@@ -104,7 +104,7 @@ Autolinker.MatchValidator = Autolinker.Util.extend( Object, {
104104
* match.
105105
*/
106106
urlMatchDoesNotHaveProtocolOrDot : function( urlMatch, protocolUrlMatch ) {
107-
return ( urlMatch && ( !protocolUrlMatch || !this.hasFullProtocolRegex.test( protocolUrlMatch ) ) && urlMatch.indexOf( '.' ) === -1 );
107+
return ( !!urlMatch && ( !protocolUrlMatch || !this.hasFullProtocolRegex.test( protocolUrlMatch ) ) && urlMatch.indexOf( '.' ) === -1 );
108108
},
109109

110110

@@ -116,11 +116,18 @@ Autolinker.MatchValidator = Autolinker.Util.extend( Object, {
116116
*
117117
* @private
118118
* @param {String} urlMatch The matched URL, if there was one. Will be an empty string if the match is not a URL match.
119+
* @param {String} protocolUrlMatch The match URL string for a protocol match. Ex: 'http://yahoo.com'. This is used to
120+
* know whether or not we have a protocol in the URL string, in order to check for a word character after the protocol
121+
* separator (':').
119122
* @return {Boolean} `true` if the URL match does not have at least one word character in it after the protocol, `false`
120123
* otherwise.
121124
*/
122-
urlMatchDoesNotHaveAtLeastOneWordChar : function( urlMatch ) {
123-
return ( urlMatch && this.hasProtocolPrefixRegex.test( urlMatch ) && !this.hasWordCharAfterProtocolRegex.test( urlMatch ) );
125+
urlMatchDoesNotHaveAtLeastOneWordChar : function( urlMatch, protocolUrlMatch ) {
126+
if( urlMatch && protocolUrlMatch ) {
127+
return !this.hasWordCharAfterProtocolRegex.test( urlMatch );
128+
} else {
129+
return false;
130+
}
124131
},
125132

126133

@@ -136,7 +143,7 @@ Autolinker.MatchValidator = Autolinker.Util.extend( Object, {
136143
* @return {Boolean} `true` if it is an invalid protocol-relative match, `false` otherwise.
137144
*/
138145
isInvalidProtocolRelativeMatch : function( protocolRelativeMatch ) {
139-
return ( protocolRelativeMatch && this.invalidProtocolRelMatchRegex.test( protocolRelativeMatch ) );
146+
return ( !!protocolRelativeMatch && this.invalidProtocolRelMatchRegex.test( protocolRelativeMatch ) );
140147
}
141148

142149
} );

src/match/Url.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
1515
* The url that was matched.
1616
*/
1717

18+
/**
19+
* @cfg {Boolean} protocolUrlMatch (required)
20+
*
21+
* `true` if the URL is a match which already has a protocol (i.e. 'http://'), `false` if the match was from a 'www' or
22+
* known TLD match.
23+
*/
24+
1825
/**
1926
* @cfg {Boolean} protocolRelativeMatch (required)
2027
*
@@ -46,13 +53,13 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
4653
protocolRelativeRegex : /^\/\//,
4754

4855
/**
49-
* @protected
50-
* @property {RegExp} checkForProtocolRegex
56+
* @private
57+
* @property {Boolean} protocolPrepended
5158
*
52-
* A regular expression used to check if the {@link #url} is missing a protocol (in which case, 'http://'
53-
* will be added).
59+
* Will be set to `true` if the 'http://' protocol has been prepended to the {@link #url} (because the
60+
* {@link #url} did not have a protocol)
5461
*/
55-
checkForProtocolRegex: /^[A-Za-z]{3,9}:/,
62+
protocolPrepended : false,
5663

5764

5865
/**
@@ -66,17 +73,19 @@ Autolinker.match.Url = Autolinker.Util.extend( Autolinker.match.Match, {
6673

6774

6875
/**
69-
* Returns the url that was matched, assuming the protocol to be 'http://' if the match
70-
* was missing a protocol.
76+
* Returns the url that was matched, assuming the protocol to be 'http://' if the original
77+
* match was missing a protocol.
7178
*
7279
* @return {String}
7380
*/
7481
getUrl : function() {
7582
var url = this.url;
7683

77-
// if the url string doesn't begin with a protocol, assume http://
78-
if( !this.protocolRelativeMatch && !this.checkForProtocolRegex.test( url ) ) {
84+
// if the url string doesn't begin with a protocol, assume 'http://'
85+
if( !this.protocolRelativeMatch && !this.protocolUrlMatch && !this.protocolPrepended ) {
7986
url = this.url = 'http://' + url;
87+
88+
this.protocolPrepended = true;
8089
}
8190

8291
return url;

0 commit comments

Comments
 (0)