|
16 | 16 |
|
17 | 17 | /*!
|
18 | 18 | * Autolinker.js
|
19 |
| - * 0.17.1 |
| 19 | + * 0.18.0 |
20 | 20 | *
|
21 | 21 | * Copyright(c) 2015 Gregory Jacobs <greg@greg-jacobs.com>
|
22 | 22 | * MIT Licensed. http://www.opensource.org/licenses/mit-license.php
|
@@ -1963,6 +1963,13 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
|
1963 | 1963 | if( this.matchHasUnbalancedClosingParen( matchStr ) ) {
|
1964 | 1964 | matchStr = matchStr.substr( 0, matchStr.length - 1 ); // remove the trailing ")"
|
1965 | 1965 | 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 | + } |
1966 | 1973 | }
|
1967 | 1974 |
|
1968 | 1975 | if( emailAddressMatch ) {
|
@@ -2058,9 +2065,52 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
|
2058 | 2065 | }
|
2059 | 2066 |
|
2060 | 2067 | 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; |
2061 | 2110 | }
|
2062 | 2111 |
|
2063 | 2112 | } );
|
| 2113 | + |
2064 | 2114 | /*global Autolinker */
|
2065 | 2115 | /*jshint scripturl:true */
|
2066 | 2116 | /**
|
|
0 commit comments