Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

parse ip addresses with protocol

  • Loading branch information...
commit 95f8f9ae83d1d0f43864fe392e5b8a1e23f2104e 1 parent 6d0acd7
@iko iko authored
View
3  flowdock-text.js
@@ -180,6 +180,7 @@ if (typeof FlowdockText === "undefined" || FlowdockText === null) {
FlowdockText.regexen.validCCTLD = regexSupplant(/(?:(?:ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|ss|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)(?=[^a-zA-Z]|$))/);
FlowdockText.regexen.validPunycode = regexSupplant(/(?:xn--[0-9a-z]+)/);
FlowdockText.regexen.validDomain = regexSupplant(/(?:#{validSubdomain}*#{validDomainName}(?:#{validGTLD}|#{validCCTLD}|#{validPunycode}))/);
+ FlowdockText.regexen.pseudoValidIP = regexSupplant(/(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/);
FlowdockText.regexen.validAsciiDomain = regexSupplant(/(?:(?:[a-z0-9#{latinAccentChars}]+)\.)+(?:#{validGTLD}|#{validCCTLD}|#{validPunycode})/gi);
FlowdockText.regexen.invalidShortDomain = regexSupplant(/^#{validDomainName}#{validCCTLD}$/);
@@ -209,7 +210,7 @@ if (typeof FlowdockText === "undefined" || FlowdockText === null) {
'(#{validPrecedingChars})' + // $2 Preceeding chracter
'(' + // $3 URL
'(https?:\\/\\/)?' + // $4 Protocol (optional)
- '(#{validDomain})' + // $5 Domain(s)
+ '(#{validDomain}|#{pseudoValidIP})' + // $5 Domain(s)
'(?::(#{validPortNumber}))?' + // $6 Port number (optional)
'(\\/#{validUrlPath}*)?' + // $7 URL Path
'(\\?#{validUrlQueryChars}*#{validUrlQueryEndingChars})?' + // $8 Query String
View
2  test/conformance.js
1 addition, 1 deletion not shown
View
8 test/conformance_tests/autolink.yml
@@ -302,10 +302,18 @@ tests:
text: "text http://example.com"
expected: "text <a href=\"http://example.com\">http://example.com</a>"
+ - description: "Autolink trailing IP"
+ text: "text http://173.194.70.101"
+ expected: "text <a href=\"http://173.194.70.101\">http://173.194.70.101</a>"
+
- description: "Autolink url in mid-text"
text: "text http://example.com more text"
expected: "text <a href=\"http://example.com\">http://example.com</a> more text"
+ - description: "Autolink IP in mid-text"
+ text: "text http://10.0.0.126 more text"
+ expected: "text <a href=\"http://10.0.0.126\">http://10.0.0.126</a> more text"
+
- description: "Autolink url in Japanese text"
text: "いまなにしてるhttp://example.comいまなにしてる"
expected: "いまなにしてる<a href=\"http://example.com\">http://example.com</a>いまなにしてる"
View
24 test/conformance_tests/extract.yml
@@ -109,6 +109,30 @@ tests:
text: "text http://somehost.com:3000"
expected: ["http://somehost.com:3000"]
+ - description: "Extract ip with protocol"
+ text: "http://127.0.0.1"
+ expected: ["http://127.0.0.1"]
+
+ - description: "Extract other ip with protocol"
+ text: "http://173.194.70.101"
+ expected: ["http://173.194.70.101"]
+
+ - description: "Extract ip with port"
+ text: "http://127.0.0.1:3000"
+ expected: ["http://127.0.0.1:3000"]
+
+ - description: "Extract ip with protocol and path"
+ text: "http://127.0.0.1/foobar"
+ expected: ["http://127.0.0.1/foobar"]
+
+ - description: "Extract ip with protocol and path ending with a slash"
+ text: "http://127.0.0.1/foobar/"
+ expected: ["http://127.0.0.1/foobar/"]
+
+ - description: "Extract ip with protocol and query params"
+ text: "http://127.0.0.1/?foo=bar"
+ expected: ["http://127.0.0.1/?foo=bar"]
+
- description: "Extract valid URL: http://xo.com/~matthew+%ff-x"
text: "text http://xo.com/~matthew+%ff-x"
expected: ["http://xo.com/~matthew+%ff-x"]
Please sign in to comment.
Something went wrong with that request. Please try again.