diff --git a/internal_packages/message-list/spec/autolinker-fixtures/medium-post-in.html b/internal_packages/message-list/spec/autolinker-fixtures/medium-post-in.html new file mode 100644 index 000000000..28ea1f256 --- /dev/null +++ b/internal_packages/message-list/spec/autolinker-fixtures/medium-post-in.html @@ -0,0 +1,5 @@ +Reported on GitHub: + +https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.3fela2o72 + +Geez they have messy URLs. diff --git a/internal_packages/message-list/spec/autolinker-fixtures/medium-post-out.html b/internal_packages/message-list/spec/autolinker-fixtures/medium-post-out.html new file mode 100644 index 000000000..56caf4500 --- /dev/null +++ b/internal_packages/message-list/spec/autolinker-fixtures/medium-post-out.html @@ -0,0 +1,5 @@ +Reported on GitHub: + +https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.3fela2o72 + +Geez they have messy URLs. diff --git a/internal_packages/message-list/spec/autolinker-fixtures/strangephones-in.html b/internal_packages/message-list/spec/autolinker-fixtures/strangephones-in.html index ee859d4c9..86c2c13a3 100644 --- a/internal_packages/message-list/spec/autolinker-fixtures/strangephones-in.html +++ b/internal_packages/message-list/spec/autolinker-fixtures/strangephones-in.html @@ -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 diff --git a/internal_packages/message-list/spec/autolinker-fixtures/strangephones-out.html b/internal_packages/message-list/spec/autolinker-fixtures/strangephones-out.html index b0761774a..183e98c4c 100644 --- a/internal_packages/message-list/spec/autolinker-fixtures/strangephones-out.html +++ b/internal_packages/message-list/spec/autolinker-fixtures/strangephones-out.html @@ -1,7 +1,19 @@ -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 +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 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 diff --git a/internal_packages/message-list/spec/autolinker-fixtures/twitter-in.html b/internal_packages/message-list/spec/autolinker-fixtures/twitter-in.html new file mode 100644 index 000000000..b923eadd4 --- /dev/null +++ b/internal_packages/message-list/spec/autolinker-fixtures/twitter-in.html @@ -0,0 +1,3 @@ +Reported on GitHub: + +https://twitter.com/SF_emergency/status/714901408298893317 diff --git a/internal_packages/message-list/spec/autolinker-fixtures/twitter-out.html b/internal_packages/message-list/spec/autolinker-fixtures/twitter-out.html new file mode 100644 index 000000000..e77d06d5a --- /dev/null +++ b/internal_packages/message-list/spec/autolinker-fixtures/twitter-out.html @@ -0,0 +1,3 @@ +Reported on GitHub: + +https://twitter.com/SF_emergency/status/714901408298893317 diff --git a/internal_packages/message-list/spec/autolinker-fixtures/url-with-port-in.html b/internal_packages/message-list/spec/autolinker-fixtures/url-with-port-in.html new file mode 100644 index 000000000..ee34575f8 --- /dev/null +++ b/internal_packages/message-list/spec/autolinker-fixtures/url-with-port-in.html @@ -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. diff --git a/internal_packages/message-list/spec/autolinker-fixtures/url-with-port-out.html b/internal_packages/message-list/spec/autolinker-fixtures/url-with-port-out.html new file mode 100644 index 000000000..227ddd62b --- /dev/null +++ b/internal_packages/message-list/spec/autolinker-fixtures/url-with-port-out.html @@ -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. diff --git a/src/regexp-utils.coffee b/src/regexp-utils.coffee index 040ba8640..5e6cbb76b 100644 --- a/src/regexp-utils.coffee +++ b/src/regexp-utils.coffee @@ -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]+)?)?' ')?' ')' ]