Merge pull request #6597 from pgkos/uri-allow-no-authority
Allow parsing URIs without authority
This commit is contained in:
commit
6c035379fe
1 changed files with 11 additions and 3 deletions
|
|
@ -178,9 +178,8 @@ proc parseUri*(uri: string, result: var Uri) =
|
||||||
i.inc(2) # Skip //
|
i.inc(2) # Skip //
|
||||||
var authority = ""
|
var authority = ""
|
||||||
i.inc parseUntil(uri, authority, {'/', '?', '#'}, i)
|
i.inc parseUntil(uri, authority, {'/', '?', '#'}, i)
|
||||||
if authority == "":
|
if authority.len > 0:
|
||||||
raise newException(ValueError, "Expected authority got nothing.")
|
parseAuthority(authority, result)
|
||||||
parseAuthority(authority, result)
|
|
||||||
else:
|
else:
|
||||||
result.opaque = true
|
result.opaque = true
|
||||||
|
|
||||||
|
|
@ -465,6 +464,15 @@ when isMainModule:
|
||||||
doAssert test.hostname == "github.com"
|
doAssert test.hostname == "github.com"
|
||||||
doAssert test.port == "dom96"
|
doAssert test.port == "dom96"
|
||||||
doAssert test.path == "/packages"
|
doAssert test.path == "/packages"
|
||||||
|
|
||||||
|
block:
|
||||||
|
let str = "file:///foo/bar/baz.txt"
|
||||||
|
let test = parseUri(str)
|
||||||
|
doAssert test.scheme == "file"
|
||||||
|
doAssert test.username == ""
|
||||||
|
doAssert test.hostname == ""
|
||||||
|
doAssert test.port == ""
|
||||||
|
doAssert test.path == "/foo/bar/baz.txt"
|
||||||
|
|
||||||
# Remove dot segments tests
|
# Remove dot segments tests
|
||||||
block:
|
block:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue