Fixes parsing of URIs that begin with '//'.

This commit is contained in:
Dominik Picheta 2015-08-23 18:22:37 +01:00
commit 193f248ea0

View file

@ -104,18 +104,22 @@ proc parseUri*(uri: string, result: var Uri) =
var i = 0 var i = 0
# Check if this is a reference URI (relative URI) # Check if this is a reference URI (relative URI)
let doubleSlash = uri.len > 1 and uri[1] == '/'
if uri[i] == '/': if uri[i] == '/':
# Make sure ``uri`` doesn't begin with '//'.
if not doubleSlash:
parsePath(uri, i, result) parsePath(uri, i, result)
return return
# Scheme # Scheme
i.inc parseWhile(uri, result.scheme, Letters + Digits + {'+', '-', '.'}, i) i.inc parseWhile(uri, result.scheme, Letters + Digits + {'+', '-', '.'}, i)
if uri[i] != ':': if uri[i] != ':' and not doubleSlash:
# Assume this is a reference URI (relative URI) # Assume this is a reference URI (relative URI)
i = 0 i = 0
result.scheme.setLen(0) result.scheme.setLen(0)
parsePath(uri, i, result) parsePath(uri, i, result)
return return
if not doubleSlash:
i.inc # Skip ':' i.inc # Skip ':'
# Authority # Authority
@ -369,6 +373,15 @@ when isMainModule:
doAssert test.path == "test/no/slash" doAssert test.path == "test/no/slash"
doAssert($test == str) doAssert($test == str)
block:
let str = "//git@github.com:dom96/packages"
let test = parseUri(str)
doAssert test.scheme == ""
doAssert test.username == "git"
doAssert test.hostname == "github.com"
doAssert test.port == "dom96"
doAssert test.path == "/packages"
# Remove dot segments tests # Remove dot segments tests
block: block:
doAssert removeDotSegments("/foo/bar/baz") == "/foo/bar/baz" doAssert removeDotSegments("/foo/bar/baz") == "/foo/bar/baz"