Skip to content

Commit 461f7cb

Browse files
committed
Merge branch 'busticated-handle_twitter_parens'
2 parents 4fa383e + c5464ba commit 461f7cb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Autolinker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
* This also includes a path, url parameters, or hash anchors. Ex: google.com/path/to/file?q1=1&q2=2#myAnchor
138138
*/
139139
matcherRegex: (function() {
140-
var twitterRegex = /(^|\s)@(\w{1,15})/, // For matching a twitter handle. Ex: @gregory_jacobs
140+
var twitterRegex = /(^|[^\w])@(\w{1,15})/, // For matching a twitter handle. Ex: @gregory_jacobs
141141

142142
emailRegex = /(?:[\-;:&=\+\$,\w\.]+@)/, // something@ for email addresses (a.k.a. local-part)
143143

tests/AutolinkerSpec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,24 @@ describe( "Autolinker", function() {
486486
} );
487487

488488

489+
it( "should automatically link twitter handles surrounded by parentheses", function() {
490+
var result = Autolinker.link( "Joe's twitter is (@joe_the_man12)" );
491+
expect( result ).toBe( 'Joe\'s twitter is (<a href="https://twitter.com/joe_the_man12" target="_blank">@joe_the_man12</a>)' );
492+
} );
493+
494+
495+
it( "should automatically link twitter handles surrounded by braces", function() {
496+
var result = Autolinker.link( "Joe's twitter is {@joe_the_man12}" );
497+
expect( result ).toBe( 'Joe\'s twitter is {<a href="https://twitter.com/joe_the_man12" target="_blank">@joe_the_man12</a>}' );
498+
} );
499+
500+
501+
it( "should automatically link twitter handles surrounded by brackets", function() {
502+
var result = Autolinker.link( "Joe's twitter is [@joe_the_man12]" );
503+
expect( result ).toBe( 'Joe\'s twitter is [<a href="https://twitter.com/joe_the_man12" target="_blank">@joe_the_man12</a>]' );
504+
} );
505+
506+
489507
it( "should automatically link multiple twitter handles in a string", function() {
490508
var result = Autolinker.link( "@greg is tweeting @joe with @josh" );
491509
expect( result ).toBe( '<a href="https://twitter.com/greg" target="_blank">@greg</a> is tweeting <a href="https://twitter.com/joe" target="_blank">@joe</a> with <a href="https://twitter.com/josh" target="_blank">@josh</a>' );

0 commit comments

Comments
 (0)