This reverts commit f4dd95f3be.
This commit is contained in:
parent
f07583588c
commit
983a2aa11c
3 changed files with 3 additions and 42 deletions
|
|
@ -299,7 +299,6 @@
|
||||||
|
|
||||||
- Added `copyWithin` [for `seq` and `array` for JavaScript targets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin).
|
- Added `copyWithin` [for `seq` and `array` for JavaScript targets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin).
|
||||||
|
|
||||||
- Added optional `strict` argument to `parseUri` of `uri` module to raise a `UriParseError` if input contains newline or tab characters, or [remove them in non-strict case](https://url.spec.whatwg.org/#concept-basic-url-parser).
|
|
||||||
|
|
||||||
## Language changes
|
## Language changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,6 @@ type
|
||||||
|
|
||||||
UriParseError* = object of ValueError
|
UriParseError* = object of ValueError
|
||||||
|
|
||||||
# https://url.spec.whatwg.org/#concept-basic-url-parser
|
|
||||||
const unsafeUrlBytesToRemove = {'\t', '\r', '\n'}
|
|
||||||
|
|
||||||
proc uriParseError*(msg: string) {.noreturn.} =
|
proc uriParseError*(msg: string) {.noreturn.} =
|
||||||
## Raises a `UriParseError` exception with message `msg`.
|
## Raises a `UriParseError` exception with message `msg`.
|
||||||
|
|
@ -263,11 +261,7 @@ func resetUri(uri: var Uri) =
|
||||||
else:
|
else:
|
||||||
f = false
|
f = false
|
||||||
|
|
||||||
func removeUnsafeBytesFromUri(uri: string): string =
|
func parseUri*(uri: string, result: var Uri) =
|
||||||
for c in uri:
|
|
||||||
if c notin unsafeUrlBytesToRemove: result.add c
|
|
||||||
|
|
||||||
func parseUri*(uri: string, result: var Uri, strict = true) =
|
|
||||||
## Parses a URI. The `result` variable will be cleared before.
|
## Parses a URI. The `result` variable will be cleared before.
|
||||||
##
|
##
|
||||||
## **See also:**
|
## **See also:**
|
||||||
|
|
@ -279,26 +273,6 @@ func parseUri*(uri: string, result: var Uri, strict = true) =
|
||||||
assert res.scheme == "https"
|
assert res.scheme == "https"
|
||||||
assert res.hostname == "nim-lang.org"
|
assert res.hostname == "nim-lang.org"
|
||||||
assert res.path == "/docs/manual.html"
|
assert res.path == "/docs/manual.html"
|
||||||
|
|
||||||
# Non-strict
|
|
||||||
res = initUri()
|
|
||||||
parseUri("https://nim-lang\n.org\t/docs/", res, strict=false)
|
|
||||||
assert res.scheme == "https"
|
|
||||||
assert res.hostname == "nim-lang.org"
|
|
||||||
assert res.path == "/docs/"
|
|
||||||
|
|
||||||
# Strict
|
|
||||||
res = initUri()
|
|
||||||
doAssertRaises(UriParseError):
|
|
||||||
parseUri("https://nim-lang\n.org\t/docs/", res)
|
|
||||||
|
|
||||||
var uri = uri
|
|
||||||
if strict:
|
|
||||||
for c in uri:
|
|
||||||
if c in unsafeUrlBytesToRemove: uriParseError("Invalid uri '$#'" % uri)
|
|
||||||
else:
|
|
||||||
uri = removeUnsafeBytesFromUri(uri)
|
|
||||||
|
|
||||||
resetUri(result)
|
resetUri(result)
|
||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
@ -335,7 +309,7 @@ func parseUri*(uri: string, result: var Uri, strict = true) =
|
||||||
# Path
|
# Path
|
||||||
parsePath(uri, i, result)
|
parsePath(uri, i, result)
|
||||||
|
|
||||||
func parseUri*(uri: string, strict = true): Uri =
|
func parseUri*(uri: string): Uri =
|
||||||
## Parses a URI and returns it.
|
## Parses a URI and returns it.
|
||||||
##
|
##
|
||||||
## **See also:**
|
## **See also:**
|
||||||
|
|
@ -346,7 +320,7 @@ func parseUri*(uri: string, strict = true): Uri =
|
||||||
assert res.password == "Password"
|
assert res.password == "Password"
|
||||||
assert res.scheme == "ftp"
|
assert res.scheme == "ftp"
|
||||||
result = initUri()
|
result = initUri()
|
||||||
parseUri(uri, result, strict)
|
parseUri(uri, result)
|
||||||
|
|
||||||
func removeDotSegments(path: string): string =
|
func removeDotSegments(path: string): string =
|
||||||
## Collapses `..` and `.` in `path` in a similar way as done in `os.normalizedPath`
|
## Collapses `..` and `.` in `path` in a similar way as done in `os.normalizedPath`
|
||||||
|
|
|
||||||
|
|
@ -141,18 +141,6 @@ template main() =
|
||||||
doAssert test.port == ""
|
doAssert test.port == ""
|
||||||
doAssert test.path == "/foo/bar/baz.txt"
|
doAssert test.path == "/foo/bar/baz.txt"
|
||||||
|
|
||||||
block: # Strict
|
|
||||||
doAssertRaises(UriParseError):
|
|
||||||
discard parseUri("https://nim-lang\n.org\t/docs/\nalert('msg\r\n')/?query\n=\tvalue#frag\nment")
|
|
||||||
|
|
||||||
# Non-strict would sanitize newline and tab characters from input
|
|
||||||
let test = parseUri("https://nim-lang\n.org\t/docs/\nalert('msg\r\n')/?query\n=\tvalue#frag\nment", strict=false)
|
|
||||||
assert test.scheme == "https"
|
|
||||||
assert test.hostname == "nim-lang.org"
|
|
||||||
assert test.path == "/docs/alert('msg')/"
|
|
||||||
assert test.query == "query=value"
|
|
||||||
assert test.anchor == "fragment"
|
|
||||||
|
|
||||||
block: # combine
|
block: # combine
|
||||||
block:
|
block:
|
||||||
let concat = combine(parseUri("http://google.com/foo/bar/"), parseUri("baz"))
|
let concat = combine(parseUri("http://google.com/foo/bar/"), parseUri("baz"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue