Skip to content

Commit ecdfa0c

Browse files
committed
better regex for email local-part
1 parent 5ed3edf commit ecdfa0c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/matcherRegexSource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
Autolinker.matcherRegex = (function() {
2222
var twitterRegex = /(^|\s)@(\w{1,15})/, // For matching a twitter handle. Ex: @gregory_jacobs
2323

24-
emailRegex = /(?:[\-;:&=\+\$,\w]+@)/, // something@ for email addresses
24+
emailRegex = /(?:[A-Za-z0-9!#$%&'*+\/=?\^_`{|}~\-]+(\.[A-Za-z0-9!#$%&'*+\/=?\^_`{|}~\-]+)*@)/, // something@ for email addresses (a.k.a. local-part), taken from https://github.com/tolsen/email-validator/blob/9f571290d1a7c2d3db35b5da86b8a310f245f48f/lib/email_validator.rb#L35
2525

2626
protocolRegex = /(?:[A-Za-z]{3,9}:(?:\/\/)?)/, // match protocol, allow in format http:// or mailto:
2727
wwwRegex = /(?:www\.)/, // starting with 'www.'

tests/AutolinkerTest.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ Ext.test.Session.addSuite( new Ext.test.Suite( {
170170
var result = Autolinker.link( "Joe's email is [email protected]" );
171171
Y.Assert.areSame( 'Joe\'s email is <a href="mailto:[email protected]" target="_blank">[email protected]</a>', result );
172172
},
173+
174+
"link() should automatically link email addresses with a period in the 'local part'" : function() {
175+
var result = Autolinker.link( "Joe's email is [email protected]" );
176+
Y.Assert.areSame( 'Joe\'s email is <a href="mailto:[email protected]" target="_blank">[email protected]</a>', result );
177+
},
173178

174179
"link() should NOT automatically link any old word with an @ character in it" : function() {
175180
var result = Autolinker.link( "Hi there@stuff" );

0 commit comments

Comments
 (0)