Skip to content

Commit 84c577b

Browse files
committed
Merge pull request #129 from simison/whitespace-phoneRegex
Use spaces instead of whitespace at phoneRegex
2 parents ac01255 + 1ed930c commit 84c577b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/matchParser/MatchParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
105105
hashtagRegex = /(^|[^\w])#(\w{1,139})/, // For matching a Hashtag. Ex: #games
106106

107107
emailRegex = /(?:[\-;:&=\+\$,\w\.]+@)/, // something@ for email addresses (a.k.a. local-part)
108-
phoneRegex = /(?:\+?\d{1,3}[-\s.])?\(?\d{3}\)?[-\s.]?\d{3}[-\s.]\d{4}/, // ex: (123) 456-7890, 123 456 7890, 123-456-7890, etc.
108+
phoneRegex = /(?:\+?\d{1,3}[-\040.])?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]\d{4}/, // ex: (123) 456-7890, 123 456 7890, 123-456-7890, etc.
109109
protocolRegex = /(?:[A-Za-z][-.+A-Za-z0-9]*:(?![A-Za-z][-.+A-Za-z0-9]*:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex)
110110
wwwRegex = /(?:www\.)/, // starting with 'www.'
111111
domainNameRegex = /[A-Za-z0-9\.\-]*[A-Za-z0-9\-]/, // anything looking at all like a domain, non-unicode domains, not ending in a period

tests/AutolinkerSpec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,13 @@ describe( "Autolinker", function() {
901901
expect( autolinker.link( "15417543010" ) ).toBe( '15417543010' );
902902
} );
903903

904+
905+
it( "should NOT automatically link numbers when there are non-space empty characters (such as newlines) in between", function() {
906+
expect( autolinker.link( "555 666 7777" ) ).toBe( '555 666 7777' );
907+
expect( autolinker.link( "555 666 7777" ) ).toBe( '555 666 7777' );
908+
expect( autolinker.link( "555\n666 7777" ) ).toBe( '555\n666 7777' );
909+
} );
910+
904911
} );
905912

906913

0 commit comments

Comments
 (0)