about summary refs log tree commit diff stats
path: root/src/types
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-08 12:09:24 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-08 12:09:24 +0200
commitbf5f9d42fb90c2d8b989e73ffe051cf62a865be1 (patch)
treef15006d723bee0848190d473a8ae6ef1114e9aca /src/types
parentb174c489ebe4393ca70f2025f3af6f5d51ec97ec (diff)
downloadchawan-bf5f9d42fb90c2d8b989e73ffe051cf62a865be1.tar.gz
url: simplify
* remove unused parseURL overload
* slightly refactor URL ctor and parseURL
Diffstat (limited to 'src/types')
-rw-r--r--src/types/url.nim36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/types/url.nim b/src/types/url.nim
index ddacaa38..456dd16d 100644
--- a/src/types/url.nim
+++ b/src/types/url.nim
@@ -707,25 +707,13 @@ func anchor*(url: URL): string =
     return url.fragment.get
   return ""
 
-proc parseURL*(input: string, base = none(URL), url: var URL,
-    override = none(URLState)): Option[URL] =
-  var url = basicParseURL(input, base, url, override)
-  if url.isNone:
-    return url
-  if url.get.scheme != "blob":
-    return url
-  url.get.blob = BlobURLEntry().some
-  return url
-
 proc parseURL*(input: string, base = none(URL), override = none(URLState)):
     Option[URL] =
-  var url = URL().some
-  url = basicParseURL(input, base, url.get, override)
+  let url = basicParseURL(input, base, stateOverride = override)
   if url.isNone:
     return url
-  if url.get.scheme != "blob":
-    return url
-  url.get.blob = BlobURLEntry().some
+  if url.get.scheme == "blob":
+    url.get.blob = some(BlobURLEntry())
   return url
 
 func serializeip(ipv4: uint32): string =
@@ -970,18 +958,14 @@ proc set*(params: URLSearchParams, name: string, value: string) {.jsfunc.} =
 
 proc newURL*(s: string, base: Option[string] = none(string)):
     JSResult[URL] {.jsctor.} =
-  if base.isSome:
-    let baseURL = parseURL(base.get)
-    if baseURL.isNone:
+  let baseURL = if base.isSome:
+    let x = parseURL(base.get)
+    if x.isNone:
       return err(newTypeError(base.get & " is not a valid URL"))
-    let url = parseURL(s, baseURL)
-    if url.isNone:
-      return err(newTypeError(s & " is not a valid URL"))
-    url.get.searchParams = newURLSearchParams()
-    url.get.searchParams.url = url
-    url.get.searchParams.initURLSearchParams(url.get.query.get(""))
-    return ok(url.get)
-  let url = parseURL(s)
+    x
+  else:
+    none(URL)
+  let url = parseURL(s, baseURL)
   if url.isNone:
     return err(newTypeError(s & " is not a valid URL"))
   url.get.searchParams = newURLSearchParams()