14
14
Autolinker . matchParser . MatchParser = Autolinker . Util . extend ( Object , {
15
15
16
16
/**
17
- * @cfg {Boolean } urls
17
+ * @cfg {Object } urls
18
18
* @inheritdoc Autolinker#urls
19
19
*/
20
20
urls : true ,
@@ -78,26 +78,31 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
78
78
* used to match protocol URLs with just a single word, like 'http://localhost',
79
79
* where we won't double check that the domain name has at least one '.'
80
80
* in it.
81
- * 7. A protocol-relative ('//') match for the case of a 'www.' prefixed
81
+ * 7. Group that matches a 'www.' prefixed URL. This is only matched if the
82
+ * 'www.' text was not prefixed by a scheme (i.e.: not prefixed by
83
+ * 'http://', 'ftp:', etc.)
84
+ * 8. A protocol-relative ('//') match for the case of a 'www.' prefixed
82
85
* URL. Will be an empty string if it is not a protocol-relative match.
83
86
* We need to know the character before the '//' in order to determine
84
87
* if it is a valid match or the // was in a string we don't want to
85
88
* auto-link.
86
- * 8. A protocol-relative ('//') match for the case of a known TLD prefixed
89
+ * 9. Group that matches a known TLD (top level domain), when a scheme
90
+ * or 'www.'-prefixed domain is not matched.
91
+ * 10. A protocol-relative ('//') match for the case of a known TLD prefixed
87
92
* URL. Will be an empty string if it is not a protocol-relative match.
88
93
* See #6 for more info.
89
- * 9. Group that is used to determine if there is a phone number match.
90
- * 10 . If there is a phone number match, and a '+' sign was included with
94
+ * 11. Group that is used to determine if there is a phone number match.
95
+ * 12 . If there is a phone number match, and a '+' sign was included with
91
96
* the phone number, this group will be populated with the '+' sign.
92
- * 11 . Group that is used to determine if there is a Hashtag match
97
+ * 13 . Group that is used to determine if there is a Hashtag match
93
98
* (i.e. \#someHashtag). Simply check for its existence to determine if
94
99
* there is a Hashtag match. The next couple of capturing groups give
95
100
* information about the Hashtag match.
96
- * 12 . The whitespace character before the #sign in a Hashtag handle. This
101
+ * 14 . The whitespace character before the #sign in a Hashtag handle. This
97
102
* is needed because there are no look-behinds in JS regular
98
103
* expressions, and can be used to reconstruct the original string in a
99
104
* replace().
100
- * 13 . The Hashtag itself in a Hashtag match. If the match is
105
+ * 15 . The Hashtag itself in a Hashtag match. If the match is
101
106
* '#someHashtag', the hashtag is 'someHashtag'.
102
107
*/
103
108
matcherRegex : ( function ( ) {
@@ -135,23 +140,23 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
135
140
136
141
'(' , // *** Capturing group $5, which is used to match a URL
137
142
'(?:' , // parens to cover match for protocol (optional), and domain
138
- '(' , // *** Capturing group $6, for a protocol -prefixed url (ex: http://google.com)
143
+ '(' , // *** Capturing group $6, for a scheme -prefixed url (ex: http://google.com)
139
144
protocolRegex . source ,
140
145
domainNameRegex . source ,
141
146
')' ,
142
147
143
148
'|' ,
144
149
145
- '(?: ' , // non-capturing paren for a 'www.' prefixed url (ex: www.google.com)
146
- '(.?//)?' , // *** Capturing group $7 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character
150
+ '(' , // *** Capturing group $7, for a 'www.' prefixed url (ex: www.google.com)
151
+ '(.?//)?' , // *** Capturing group $8 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character
147
152
wwwRegex . source ,
148
153
domainNameRegex . source ,
149
154
')' ,
150
155
151
156
'|' ,
152
157
153
- '(?: ' , // non-capturing paren for known a TLD url (ex: google.com)
154
- '(.?//)?' , // *** Capturing group $8 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character
158
+ '(' , // *** Capturing group $9, for known a TLD url (ex: google.com)
159
+ '(.?//)?' , // *** Capturing group $10 for an optional protocol-relative URL. Must be at the beginning of the string or start with a non-word character
155
160
domainNameRegex . source ,
156
161
tldRegex . source ,
157
162
')' ,
@@ -163,17 +168,17 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
163
168
'|' ,
164
169
165
170
// this setup does not scale well for open extension :( Need to rethink design of autolinker...
166
- // *** Capturing group $9 , which matches a (USA for now) phone number, and
167
- // *** Capturing group $10 , which matches the '+' sign for international numbers, if it exists
171
+ // *** Capturing group $11 , which matches a (USA for now) phone number, and
172
+ // *** Capturing group $12 , which matches the '+' sign for international numbers, if it exists
168
173
'(' ,
169
174
phoneRegex . source ,
170
175
')' ,
171
176
172
177
'|' ,
173
178
174
- '(' , // *** Capturing group $11 , which can be used to check for a Hashtag match. Use group $12 for the actual Hashtag though. $11 may be used to reconstruct the original string in a replace()
175
- // *** Capturing group $12 , which matches the whitespace character before the '#' sign (needed because of no lookbehinds), and
176
- // *** Capturing group $13 , which matches the actual Hashtag
179
+ '(' , // *** Capturing group $13 , which can be used to check for a Hashtag match. Use group $12 for the actual Hashtag though. $11 may be used to reconstruct the original string in a replace()
180
+ // *** Capturing group $14 , which matches the whitespace character before the '#' sign (needed because of no lookbehinds), and
181
+ // *** Capturing group $15 , which matches the actual Hashtag
177
182
hashtagRegex . source ,
178
183
')'
179
184
] . join ( "" ) , 'gi' ) ;
@@ -230,8 +235,8 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
230
235
replace : function ( text , replaceFn , contextObj ) {
231
236
var me = this ; // for closure
232
237
233
- return text . replace ( this . matcherRegex , function ( matchStr , $1 , $2 , $3 , $4 , $5 , $6 , $7 , $8 , $9 , $10 , $11 , $12 , $13 ) {
234
- var matchDescObj = me . processCandidateMatch ( matchStr , $1 , $2 , $3 , $4 , $5 , $6 , $7 , $8 , $9 , $10 , $11 , $12 , $13 ) ; // "match description" object
238
+ return text . replace ( this . matcherRegex , function ( matchStr /* , $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15*/ ) {
239
+ var matchDescObj = me . processCandidateMatch . apply ( me , arguments ) ; // "match description" object
235
240
236
241
// Return out with no changes for match types that are disabled (url,
237
242
// email, phone, etc.), or for matches that are invalid (false
@@ -271,12 +276,17 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
271
276
* @param {String } emailAddressMatch The matched email address for an email
272
277
* address match.
273
278
* @param {String } urlMatch The matched URL string for a URL match.
274
- * @param {String } protocolUrlMatch The match URL string for a protocol
279
+ * @param {String } schemeUrlMatch The match URL string for a protocol
275
280
* match. Ex: 'http://yahoo.com'. This is used to match something like
276
281
* 'http://localhost', where we won't double check that the domain name
277
282
* has at least one '.' in it.
283
+ * @param {String } wwwMatch The matched string of a 'www.'-prefixed URL that
284
+ * was matched. This is only matched if the 'www.' text was not prefixed
285
+ * by a scheme (i.e.: not prefixed by 'http://', 'ftp:', etc.).
278
286
* @param {String } wwwProtocolRelativeMatch The '//' for a protocol-relative
279
287
* match from a 'www' url, with the character that comes before the '//'.
288
+ * @param {String } tldMatch The matched string of a known TLD (top level
289
+ * domain), when a scheme or 'www.'-prefixed domain is not matched.
280
290
* @param {String } tldProtocolRelativeMatch The '//' for a protocol-relative
281
291
* match from a TLD (top level domain) match, with the character that
282
292
* comes before the '//'.
@@ -308,8 +318,8 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
308
318
*/
309
319
processCandidateMatch : function (
310
320
matchStr , twitterMatch , twitterHandlePrefixWhitespaceChar , twitterHandle ,
311
- emailAddressMatch , urlMatch , protocolUrlMatch , wwwProtocolRelativeMatch ,
312
- tldProtocolRelativeMatch , phoneMatch , phonePlusSignMatch , hashtagMatch ,
321
+ emailAddressMatch , urlMatch , schemeUrlMatch , wwwMatch , wwwProtocolRelativeMatch ,
322
+ tldMatch , tldProtocolRelativeMatch , phoneMatch , phonePlusSignMatch , hashtagMatch ,
313
323
hashtagPrefixWhitespaceChar , hashtag
314
324
) {
315
325
// Note: The `matchStr` variable wil be fixed up to remove characters that are no longer needed (which will
@@ -319,19 +329,23 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
319
329
match , // Will be an Autolinker.match.Match object
320
330
321
331
prefixStr = "" , // A string to use to prefix the anchor tag that is created. This is needed for the Twitter and Hashtag matches.
322
- suffixStr = "" ; // A string to suffix the anchor tag that is created. This is used if there is a trailing parenthesis that should not be auto-linked.
332
+ suffixStr = "" , // A string to suffix the anchor tag that is created. This is used if there is a trailing parenthesis that should not be auto-linked.
333
+
334
+ urls = this . urls ; // the 'urls' config
323
335
324
336
// Return out with `null` for match types that are disabled (url, email,
325
337
// twitter, hashtag), or for matches that are invalid (false positives
326
338
// from the matcherRegex, which can't use look-behinds since they are
327
339
// unavailable in JS).
328
340
if (
329
- ( urlMatch && ! this . urls ) ||
341
+ ( schemeUrlMatch && ! urls . schemeMatches ) ||
342
+ ( wwwMatch && ! urls . wwwMatches ) ||
343
+ ( tldMatch && ! urls . tldMatches ) ||
330
344
( emailAddressMatch && ! this . email ) ||
331
345
( phoneMatch && ! this . phone ) ||
332
346
( twitterMatch && ! this . twitter ) ||
333
347
( hashtagMatch && ! this . hashtag ) ||
334
- ! this . matchValidator . isValidMatch ( urlMatch , protocolUrlMatch , protocolRelativeMatch )
348
+ ! this . matchValidator . isValidMatch ( urlMatch , schemeUrlMatch , protocolRelativeMatch )
335
349
) {
336
350
return null ;
337
351
}
@@ -344,7 +358,7 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
344
358
suffixStr = ")" ; // this will be added after the generated <a> tag
345
359
} else {
346
360
// Handle an invalid character after the TLD
347
- var pos = this . matchHasInvalidCharAfterTld ( urlMatch , protocolUrlMatch ) ;
361
+ var pos = this . matchHasInvalidCharAfterTld ( urlMatch , schemeUrlMatch ) ;
348
362
if ( pos > - 1 ) {
349
363
suffixStr = matchStr . substr ( pos ) ; // this will be added after the generated <a> tag
350
364
matchStr = matchStr . substr ( 0 , pos ) ; // remove the trailing invalid chars
@@ -396,7 +410,7 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
396
410
match = new Autolinker . match . Url ( {
397
411
matchedText : matchStr ,
398
412
url : matchStr ,
399
- protocolUrlMatch : ! ! protocolUrlMatch ,
413
+ protocolUrlMatch : ! ! schemeUrlMatch ,
400
414
protocolRelativeMatch : ! ! protocolRelativeMatch ,
401
415
stripPrefix : this . stripPrefix
402
416
} ) ;
0 commit comments