Skip to content

Commit be40b98

Browse files
authored
Merge pull request #20 from ljosa/gh-19
Parse literal IPv6 addresses in hostnames
2 parents 67900b8 + da618d6 commit be40b98

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/org/bovinegenius/exploding_fish/parser.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
(defn generic
3232
"Takes a URI string and parses it into scheme, scheme-relative,
33-
and fragment parts."
33+
and fragment parts."
3434
[^String uri]
3535
(if uri
3636
(let [[_ scheme ssp fragment] (or (re-find #"^([a-zA-Z][a-zA-Z\d+.-]*):([^#]+)#?(.*)$" uri)
@@ -60,7 +60,7 @@ parts."
6060
"Parse the authority part into user-info, hostname, and port parts."
6161
[authority]
6262
(if authority
63-
(let [[_ user-info host port] (re-find #"^([^@]+(?=@))?@?([^:]+):?(.*)$" authority)
63+
(let [[_ user-info host port] (re-find #"^([^@]+(?=@))?@?([^:]+|\[[0-9a-fA-F:]*\]):?(\d*)$" authority)
6464
port (if (empty? port) nil (Integer/parseInt port))]
6565
{:user-info user-info :host host :port port})
6666
{:user-info nil :host nil :port nil}))

test/org/bovinegenius/uri_test.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
:authority "www.fred.net",
3131
:scheme "http",
3232
:scheme-relative "//www.fred.net/"})))
33+
(let [uri-string "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"]
34+
(is (= (into {} (uri uri-string))
35+
{:scheme "http"
36+
:scheme-relative "//[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"
37+
:authority "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80"
38+
:host "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]"
39+
:port 80
40+
:path "/index.html"})))
3341
(let [uri-string "http://www.domain.net/with?query=and#fragment"]
3442
(is (= (into {} (uri uri-string))
3543
(into {} (uri (URI. uri-string)))

0 commit comments

Comments
 (0)