Fixes issues with URI concatenation when URI has no path.
This commit is contained in:
parent
5dca695bcf
commit
1dc6caea6b
1 changed files with 11 additions and 2 deletions
|
|
@ -278,7 +278,9 @@ proc `/`*(x: Uri, path: string): Uri =
|
||||||
result = x
|
result = x
|
||||||
|
|
||||||
if result.path.len == 0:
|
if result.path.len == 0:
|
||||||
result.path = path
|
if path[0] != '/':
|
||||||
|
result.path = "/"
|
||||||
|
result.path.add(path)
|
||||||
return
|
return
|
||||||
|
|
||||||
if result.path[result.path.len-1] == '/':
|
if result.path[result.path.len-1] == '/':
|
||||||
|
|
@ -476,6 +478,11 @@ when isMainModule:
|
||||||
let foo = parseUri("http://example.com") / "/baz"
|
let foo = parseUri("http://example.com") / "/baz"
|
||||||
doAssert foo.path == "/baz"
|
doAssert foo.path == "/baz"
|
||||||
|
|
||||||
|
# bug found on stream 13/10/17
|
||||||
|
block:
|
||||||
|
let foo = parseUri("http://localhost:9515") / "status"
|
||||||
|
doAssert $foo == "http://localhost:9515/status"
|
||||||
|
|
||||||
# isAbsolute tests
|
# isAbsolute tests
|
||||||
block:
|
block:
|
||||||
doAssert "www.google.com".parseUri().isAbsolute() == false
|
doAssert "www.google.com".parseUri().isAbsolute() == false
|
||||||
|
|
@ -515,4 +522,6 @@ when isMainModule:
|
||||||
doAssert "https://example.com/about".parseUri().isAbsolute == true
|
doAssert "https://example.com/about".parseUri().isAbsolute == true
|
||||||
doAssert "https://example.com/about/staff.html".parseUri().isAbsolute == true
|
doAssert "https://example.com/about/staff.html".parseUri().isAbsolute == true
|
||||||
doAssert "https://example.com/about/staff.html?".parseUri().isAbsolute == true
|
doAssert "https://example.com/about/staff.html?".parseUri().isAbsolute == true
|
||||||
doAssert "https://example.com/about/staff.html?parameters".parseUri().isAbsolute == true
|
doAssert "https://example.com/about/staff.html?parameters".parseUri().isAbsolute == true
|
||||||
|
|
||||||
|
echo("All good!")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue