@@ -8,12 +8,6 @@ import { tldRegex } from "./tld-regex";
88// For debugging: search for other "For debugging" lines
99// import CliTable from 'cli-table';
1010
11- /**
12- * Stricter TLD regex which adds a beginning and end check to ensure
13- * the string is a valid TLD.
14- */
15- const strictTldRegex = new RegExp ( `^${ tldRegex . source } $` ) ;
16-
1711/**
1812 * @class Autolinker.matcher.Email
1913 * @extends Autolinker.matcher.Matcher
@@ -30,6 +24,12 @@ export class EmailMatcher extends Matcher {
3024 */
3125 protected localPartCharRegex = new RegExp ( `[${ alphaNumericAndMarksCharsStr } !#$%&'*+/=?^_\`{|}~-]` ) ;
3226
27+ /**
28+ * Stricter TLD regex which adds a beginning and end check to ensure
29+ * the string is a valid TLD
30+ */
31+ protected strictTldRegex = new RegExp ( `^${ tldRegex . source } $` ) ;
32+
3333 /**
3434 * Valid URI scheme for email address URLs
3535 */
@@ -42,6 +42,7 @@ export class EmailMatcher extends Matcher {
4242 parseMatches ( text : string ) {
4343 const tagBuilder = this . tagBuilder ,
4444 localPartCharRegex = this . localPartCharRegex ,
45+ strictTldRegex = this . strictTldRegex ,
4546 mailToScheme = this . mailToScheme ,
4647 matches : Match [ ] = [ ] ,
4748 len = text . length ,
@@ -226,10 +227,10 @@ export class EmailMatcher extends Matcher {
226227 * @param {string } emailAddress - email address
227228 * @return {Boolean } - true is email have valid TLD, false otherwise
228229 */
229- function doesEmailHaveValidTld ( emailAddress : string ) {
230- const emailAddressTld : string = emailAddress . split ( '.' ) . pop ( ) || '' ;
230+ function doesEmailHaveValidTld ( emailAddress : string ) {
231+ const emailAddressTld : string = emailAddress . split ( '.' ) . pop ( ) || '' ;
231232 const emailAddressNormalized = emailAddressTld . toLowerCase ( ) ;
232- const isValidTld = strictTldRegex . test ( emailAddressNormalized ) ;
233+ const isValidTld = strictTldRegex . test ( emailAddressNormalized ) ;
233234
234235 return isValidTld ;
235236 }
@@ -265,7 +266,7 @@ export class EmailMatcher extends Matcher {
265266 }
266267
267268 // if the email address has a valid TLD, add it to the list of matches
268- if ( doesEmailHaveValidTld ( emailAddress ) ) {
269+ if ( doesEmailHaveValidTld ( emailAddress ) ) {
269270 matches . push ( new EmailMatch ( {
270271 tagBuilder : tagBuilder ,
271272 matchedText : matchedText ,
0 commit comments