summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2021-05-09 23:33:31 +0200
committerGitHub <noreply@github.com>2021-05-09 23:33:31 +0200
commit983a2aa11c397624d8a366d29184557ba1120f8d (patch)
tree17084ebc9e6a447a0e3e8ed711b480c6af4489b4 /lib
parentf07583588c67f9f3f8dfd7eb44befb5101392d71 (diff)
downloadNim-983a2aa11c397624d8a366d29184557ba1120f8d.tar.gz
Revert "Fix parseUri to sanitize urls containing ASCII newline or tab (#17967)" (#17984)
This reverts commit f4dd95f3bee14b69caec63c3be984c4a75f43c8a.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/uri.nim32
1 files changed, 3 insertions, 29 deletions
diff --git a/lib/pure/uri.nim b/lib/pure/uri.nim
index 67d5e5933..a828298c2 100644
--- a/lib/pure/uri.nim
+++ b/lib/pure/uri.nim
@@ -51,8 +51,6 @@ type
 
   UriParseError* = object of ValueError
 
-# https://url.spec.whatwg.org/#concept-basic-url-parser
-const unsafeUrlBytesToRemove = {'\t', '\r', '\n'}
 
 proc uriParseError*(msg: string) {.noreturn.} =
   ## Raises a `UriParseError` exception with message `msg`.
@@ -263,11 +261,7 @@ func resetUri(uri: var Uri) =
     else:
       f = false
 
-func removeUnsafeBytesFromUri(uri: string): string =
-  for c in uri:
-    if c notin unsafeUrlBytesToRemove: result.add c
-
-func parseUri*(uri: string, result: var Uri, strict = true) =
+func parseUri*(uri: string, result: var Uri) =
   ## Parses a URI. The `result` variable will be cleared before.
   ##
   ## **See also:**
@@ -279,26 +273,6 @@ func parseUri*(uri: string, result: var Uri, strict = true) =
     assert res.scheme == "https"
     assert res.hostname == "nim-lang.org"
     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)
 
   var i = 0
@@ -335,7 +309,7 @@ func parseUri*(uri: string, result: var Uri, strict = true) =
   # Path
   parsePath(uri, i, result)
 
-func parseUri*(uri: string, strict = true): Uri =
+func parseUri*(uri: string): Uri =
   ## Parses a URI and returns it.
   ##
   ## **See also:**
@@ -346,7 +320,7 @@ func parseUri*(uri: string, strict = true): Uri =
     assert res.password == "Password"
     assert res.scheme == "ftp"
   result = initUri()
-  parseUri(uri, result, strict)
+  parseUri(uri, result)
 
 func removeDotSegments(path: string): string =
   ## Collapses `..` and `.` in `path` in a similar way as done in `os.normalizedPath`