File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,10 @@ describe("autolinker", function () {
9090 [ "partl@mail.boku.ac.at" , "mailto:partl@mail.boku.ac.at" ] ,
9191 [ "Irene.Hyna@bmwf.ac.at" , "mailto:Irene.Hyna@bmwf.ac.at" ] ,
9292 [ "<hi@foo.bar.baz>" , "mailto:hi@foo.bar.baz" ] ,
93+ [
94+ "foo@用户@例子.广告" ,
95+ "mailto:%E7%94%A8%E6%88%B7@%E4%BE%8B%E5%AD%90.%E5%B9%BF%E5%91%8A" ,
96+ ] ,
9397 ] ) ;
9498 } ) ;
9599
@@ -144,6 +148,7 @@ describe("autolinker", function () {
144148 "http//[]" , // Empty IPv6 address.
145149 "abc.example.com" , // URL without scheme.
146150 "JD?M$0QP)lKn06l1apKDC@\\qJ4B!!(5m+j.7F790m" , // Not a valid email.
151+ "262@0.302304" , // Invalid domain.
147152 ] . join ( "\n" )
148153 ) ;
149154 expect ( matches . length ) . toEqual ( 0 ) ;
Original file line number Diff line number Diff line change @@ -133,10 +133,12 @@ class Autolinker {
133133
134134 static #regex;
135135
136+ static #numericTLDRegex;
137+
136138 static findLinks ( text ) {
137139 // Regex can be tested and verified at https://regex101.com/r/rXoLiT/2.
138140 this . #regex ??=
139- / \b (?: h t t p s ? : \/ \/ | m a i l t o : | w w w \. ) (?: [ \S - - [ \p{ P} < > ] ] | \/ | [ \S - - [ \[ \] ] ] + [ \S - - [ \p{ P} < > ] ] ) + | \b [ \S - - [ @ \p{ Ps} \p{ Pe} < > ] ] + @ ( [ \S - - [ \p{ P} < > ] ] + (?: \. [ \S - - [ \p{ P} < > ] ] + ) + ) / gmv;
141+ / \b (?: h t t p s ? : \/ \/ | m a i l t o : | w w w \. ) (?: [ \S - - [ \p{ P} < > ] ] | \/ | [ \S - - [ \[ \] ] ] + [ \S - - [ \p{ P} < > ] ] ) + | (? = \p { L } ) [ \S - - [ @ \p{ Ps} \p{ Pe} < > ] ] + @ ( [ \S - - [ \p{ P} < > ] ] + (?: \. [ \S - - [ \p{ P} < > ] ] + ) + ) / gmv;
140142
141143 const [ normalizedText , diffs ] = normalize ( text , { ignoreDashEOL : true } ) ;
142144 const matches = normalizedText . matchAll ( this . #regex) ;
@@ -150,11 +152,19 @@ class Autolinker {
150152 url . startsWith ( "https://" )
151153 ) {
152154 raw = url ;
153- } else if ( URL . canParse ( `http://${ emailDomain } ` ) ) {
154- raw = url . startsWith ( "mailto:" ) ? url : `mailto:${ url } ` ;
155- } else {
156- continue ;
155+ } else if ( emailDomain ) {
156+ const hostname = URL . parse ( `http://${ emailDomain } ` ) ?. hostname ;
157+ if ( ! hostname ) {
158+ continue ;
159+ }
160+ this . #numericTLDRegex ??= / \. \d + $ / ;
161+ if ( this . #numericTLDRegex. test ( hostname ) ) {
162+ // Skip emails with a numeric TLD as domain.
163+ continue ;
164+ }
157165 }
166+ raw ??= url . startsWith ( "mailto:" ) ? url : `mailto:${ url } ` ;
167+
158168 const absoluteURL = createValidAbsoluteUrl ( raw , null , {
159169 addDefaultProtocol : true ,
160170 } ) ;
You can’t perform that action at this time.
0 commit comments