diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-05-04 16:02:50 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-05-04 16:02:50 +0200 |
commit | 764cc0217735454c166cb7dd490db58f5fa6fe26 (patch) | |
tree | 63633b39ae24815e8b677ccbc9bac2cb01c39d3b /lib/pure/uri.nim | |
parent | afa80092d378a6dbc116c0aa3ed3964fd8c599d6 (diff) | |
parent | c1aa973758a60d7ef0e698c94861b74132612de5 (diff) | |
download | Nim-764cc0217735454c166cb7dd490db58f5fa6fe26.tar.gz |
Merge branch 'devel' into araq
Diffstat (limited to 'lib/pure/uri.nim')
-rw-r--r-- | lib/pure/uri.nim | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/pure/uri.nim b/lib/pure/uri.nim index ba745cfd3..c7e0ed1da 100644 --- a/lib/pure/uri.nim +++ b/lib/pure/uri.nim @@ -50,6 +50,7 @@ proc add*(url: var Url, a: Url) {.deprecated.} = proc parseAuthority(authority: string, result: var Uri) = var i = 0 var inPort = false + var inIPv6 = false while true: case authority[i] of '@': @@ -59,7 +60,14 @@ proc parseAuthority(authority: string, result: var Uri) = result.hostname.setLen(0) inPort = false of ':': - inPort = true + if inIPv6: + result.hostname.add(authority[i]) + else: + inPort = true + of '[': + inIPv6 = true + of ']': + inIPv6 = false of '\0': break else: if inPort: @@ -346,6 +354,17 @@ when isMainModule: doAssert($test == str) block: + # IPv6 address + let str = "foo://[::1]:1234/bar?baz=true&qux#quux" + let uri = parseUri(str) + doAssert uri.scheme == "foo" + doAssert uri.hostname == "::1" + doAssert uri.port == "1234" + doAssert uri.path == "/bar" + doAssert uri.query == "baz=true&qux" + doAssert uri.anchor == "quux" + + block: let str = "urn:example:animal:ferret:nose" let test = parseUri(str) doAssert test.scheme == "urn" |