summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorpgkos <pg.kosinski@gmail.com>2017-10-25 18:54:34 +0200
committerGitHub <noreply@github.com>2017-10-25 18:54:34 +0200
commita20326e2682486be95c33cf5cb23fe1cafe70979 (patch)
tree98379a11c9d35c722fbeaa997a41e037abcfbc80 /lib/pure
parentfa02ffaeba219ca3f259667d5161d30e47bb13e0 (diff)
downloadNim-a20326e2682486be95c33cf5cb23fe1cafe70979.tar.gz
Allow parsing URIs without authority
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/uri.nim16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/pure/uri.nim b/lib/pure/uri.nim
index 4b2e4e052..2af5412d1 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!")