From a20326e2682486be95c33cf5cb23fe1cafe70979 Mon Sep 17 00:00:00 2001 From: pgkos Date: Wed, 25 Oct 2017 18:54:34 +0200 Subject: [PATCH] Allow parsing URIs without authority --- lib/pure/uri.nim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/pure/uri.nim b/lib/pure/uri.nim index 4b2e4e052d..2af5412d13 100644 --- a/lib/pure/uri.nim +++ b/lib/pure/uri.nim @@ -135,9 +135,8 @@ proc parseUri*(uri: string, result: var Uri) = i.inc(2) # Skip // var authority = "" i.inc parseUntil(uri, authority, {'/', '?', '#'}, i) - if authority == "": - raise newException(ValueError, "Expected authority got nothing.") - parseAuthority(authority, result) + if authority.len > 0: + parseAuthority(authority, result) else: result.opaque = true @@ -412,6 +411,15 @@ when isMainModule: doAssert test.hostname == "github.com" doAssert test.port == "dom96" 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 block: @@ -524,4 +532,4 @@ when isMainModule: doAssert "https://example.com/about/staff.html?".parseUri().isAbsolute == true doAssert "https://example.com/about/staff.html?parameters".parseUri().isAbsolute == true - echo("All good!") \ No newline at end of file + echo("All good!")