fix(autolinker): Update regexp to handle reported failure cases

This commit is contained in:
Ben Gotow 2016-03-31 16:36:13 -07:00
parent bec4a86629
commit 9a588dbda6
9 changed files with 60 additions and 9 deletions

View file

@ -0,0 +1,5 @@
Reported on GitHub:
https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.3fela2o72
Geez they have messy URLs.

View file

@ -0,0 +1,5 @@
Reported on GitHub:
<a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.3fela2o72" title="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.3fela2o72">https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.3fela2o72</a>
Geez they have messy URLs.

View file

@ -1,7 +1,19 @@
Give us a call at 540-250-1231. Thanks!
Give us a call at +1540-250-1231. Thanks!
Give us a call at +1-540-250-1231. Thanks!
Give us a call at 1-540-250-1231. Thanks!
Give us a call at +1-(540)-250-1231. Thanks!
Give us a call at (540)-250-1231. Thanks!
Give us a call at (540) 250 1231. Thanks!
Give us a call at 540 250 1231. Thanks!
Give us a call at +1 540 250 1231. Thanks!
Give us a call at 6641234567. Thanks!
Give us a call at 664 123 4567. Thanks!
Give us a call at (044) 664 123 4567. Thanks!
Give us a call at 0333 320 1030. Thanks!
123123-1223-12-312-31-23-123123-12341515124124-123124
1111123123123-1231
123123123123123123123123123123123
Here's the number:(540) 250 1231

View file

@ -1,7 +1,19 @@
Give us a call at<a href="tel: 540-250-1231" title="tel: 540-250-1231"> 540-250-1231</a>. Thanks!
Give us a call at<a href="tel: 540 250 1231" title="tel: 540 250 1231"> 540 250 1231</a>. Thanks!
Give us a call at <a href="tel:540-250-1231" title="tel:540-250-1231">540-250-1231</a>. Thanks!
Give us a call at <a href="tel:+1540-250-1231" title="tel:+1540-250-1231">+1540-250-1231</a>. Thanks!
Give us a call at <a href="tel:+1-540-250-1231" title="tel:+1-540-250-1231">+1-540-250-1231</a>. Thanks!
Give us a call at <a href="tel:1-540-250-1231" title="tel:1-540-250-1231">1-540-250-1231</a>. Thanks!
Give us a call at <a href="tel:+1-(540)-250-1231" title="tel:+1-(540)-250-1231">+1-(540)-250-1231</a>. Thanks!
Give us a call at <a href="tel:(540)-250-1231" title="tel:(540)-250-1231">(540)-250-1231</a>. Thanks!
Give us a call at <a href="tel:(540) 250 1231" title="tel:(540) 250 1231">(540) 250 1231</a>. Thanks!
Give us a call at <a href="tel:540 250 1231" title="tel:540 250 1231">540 250 1231</a>. Thanks!
Give us a call at <a href="tel:+1 540 250 1231" title="tel:+1 540 250 1231">+1 540 250 1231</a>. Thanks!
Give us a call at<a href="tel: 6641234567" title="tel: 6641234567"> 6641234567</a>. Thanks!
Give us a call at<a href="tel: 664 123 4567" title="tel: 664 123 4567"> 664 123 4567</a>. Thanks!
Give us a call at (044)<a href="tel: 664 123 4567" title="tel: 664 123 4567"> 664 123 4567</a>. Thanks!
Give us a call at 6641234567. Thanks!
Give us a call at <a href="tel:664 123 4567" title="tel:664 123 4567">664 123 4567</a>. Thanks!
Give us a call at <a href="tel:(044) 664 123 4567" title="tel:(044) 664 123 4567">(044) 664 123 4567</a>. Thanks!
Give us a call at <a href="tel:0333 320 1030" title="tel:0333 320 1030">0333 320 1030</a>. Thanks!
123123-1223-12-312-31-23-123123-12341515124124-123124
1111123123123-1231
123123123123123123123123123123123
Here's the number:<a href="tel:(540) 250 1231" title="tel:(540) 250 1231">(540) 250 1231</a>

View file

@ -0,0 +1,3 @@
Reported on GitHub:
https://twitter.com/SF_emergency/status/714901408298893317

View file

@ -0,0 +1,3 @@
Reported on GitHub:
<a href="https://twitter.com/SF_emergency/status/714901408298893317" title="https://twitter.com/SF_emergency/status/714901408298893317">https://twitter.com/SF_emergency/status/714901408298893317</a>

View file

@ -0,0 +1,2 @@
HTTP links with port in them don't link correctly either,
e.g. http://example.com:8080/path/ only links http://example.com.

View file

@ -0,0 +1,2 @@
HTTP links with port in them don't link correctly either,
e.g. <a href="http://example.com:8080/path/" title="http://example.com:8080/path/">http://example.com:8080/path/</a> only links <a href="http://example.com" title="http://example.com">http://example.com</a>.

View file

@ -15,7 +15,10 @@ RegExpUtils =
emailRegex: -> new RegExp(/([a-z.A-Z0-9!#$%&'*+\-/=?^_`{|}~;:]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,63})/g)
# http://stackoverflow.com/questions/16631571/javascript-regular-expression-detect-all-the-phone-number-from-the-page-source
phoneRegex: -> new RegExp(/(?:\+?(\d{1,3}))?[- (]*(\d{3})[- )]*(\d{3})[- ]*(\d{4})(?: *x(\d+))?\b/g)
# http://www.regexpal.com/?fam=94521
# NOTE: This is not exhaustive, and balances what is technically a phone number
# with what would be annoying to linkify. eg: 12223334444 does not match.
phoneRegex: -> new RegExp(/([\+\(]+|\b)(?:(\d{1,3}[- ()]*)?)(\d{3})[- )]+(\d{3})[- ]+(\d{4})(?: *x(\d+))?\b/g)
# http://stackoverflow.com/a/16463966
# http://www.regexpal.com/?fam=93928
@ -77,6 +80,9 @@ RegExpUtils =
')'
')'
# :port (optional)
'(?::\d*)?'
'|'
# mailto:username@password.com
@ -87,10 +93,11 @@ RegExpUtils =
'('
# URL components
# (last character must not be puncation, hence two groups)
'(?:[\\+~%\\/\\.\\w\\-_]*[\\+~%\\/\\w\\-_]+)?'
# optionally followed by a query string
'(?:[\\+~%\\/\\.\\w\\-_@]*[\\+~%\\/\\w\\-_]+)?'
# optionally followed by: a query string and/or a #location
# (last character must not be puncation, hence two groups)
'(?:(\\?[\\-\\+=&;%@\\.\\w_]*[\\-\\+=&;%@\\w_\\/]+)#?(?:[\\.\\!\\/\\\\\\w]*[\\/\\\\\\w]+)?)?'
'(?:(\\?[\\-\\+=&;%@\\.\\w_]*[\\-\\+=&;%@\\w_\\/]+)?#?(?:[\\.\\!\\/\\\\\\w]*[\\/\\\\\\w]+)?)?'
')?'
')'
]