Skip to content

Commit b720a8e

Browse files
committed
Build 0.18.0
1 parent 4a8b50f commit b720a8e

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

dist/Autolinker.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/*!
1818
* Autolinker.js
19-
* 0.17.1
19+
* 0.18.0
2020
*
2121
* Copyright(c) 2015 Gregory Jacobs <greg@greg-jacobs.com>
2222
* MIT Licensed. http://www.opensource.org/licenses/mit-license.php
@@ -1963,6 +1963,13 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
19631963
if( this.matchHasUnbalancedClosingParen( matchStr ) ) {
19641964
matchStr = matchStr.substr( 0, matchStr.length - 1 ); // remove the trailing ")"
19651965
suffixStr = ")"; // this will be added after the generated <a> tag
1966+
} else {
1967+
// Handle an invalid character after the TLD
1968+
var pos = this.matchHasInvalidCharAfterTld( urlMatch, protocolUrlMatch );
1969+
if( pos > -1 ) {
1970+
suffixStr = matchStr.substr(pos); // this will be added after the generated <a> tag
1971+
matchStr = matchStr.substr( 0, pos ); // remove the trailing invalid chars
1972+
}
19661973
}
19671974

19681975
if( emailAddressMatch ) {
@@ -2058,9 +2065,52 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
20582065
}
20592066

20602067
return false;
2068+
},
2069+
2070+
2071+
/**
2072+
* Determine if there's an invalid character after the TLD in a URL. Valid
2073+
* characters after TLD are ':/?#'. Exclude protocol matched URLs from this
2074+
* check.
2075+
*
2076+
* @private
2077+
* @param {String} urlMatch The matched URL, if there was one. Will be an
2078+
* empty string if the match is not a URL match.
2079+
* @param {String} protocolUrlMatch The match URL string for a protocol
2080+
* match. Ex: 'http://yahoo.com'. This is used to match something like
2081+
* 'http://localhost', where we won't double check that the domain name
2082+
* has at least one '.' in it.
2083+
* @return {Number} the position where the invalid character was found. If
2084+
* no such character was found, returns -1
2085+
*/
2086+
matchHasInvalidCharAfterTld : function( urlMatch, protocolUrlMatch ) {
2087+
if ( !urlMatch ) {
2088+
return -1;
2089+
}
2090+
2091+
var offset = 0;
2092+
if ( protocolUrlMatch ) {
2093+
offset = urlMatch.indexOf(':');
2094+
urlMatch = urlMatch.slice(offset);
2095+
}
2096+
2097+
var re = /^((.?\/\/)?[A-Za-z0-9\.\-]*[A-Za-z0-9\-]\.[A-Za-z]+)/;
2098+
var res = re.exec( urlMatch );
2099+
if ( res === null ) {
2100+
return -1;
2101+
}
2102+
2103+
offset += res[1].length;
2104+
urlMatch = urlMatch.slice(res[1].length);
2105+
if (/^[^.A-Za-z:\/?#]/.test(urlMatch)) {
2106+
return offset;
2107+
}
2108+
2109+
return -1;
20612110
}
20622111

20632112
} );
2113+
20642114
/*global Autolinker */
20652115
/*jshint scripturl:true */
20662116
/**

0 commit comments

Comments
 (0)