diff options
author | bptato <nincsnevem662@gmail.com> | 2023-09-01 17:56:36 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-09-01 17:56:36 +0200 |
commit | b06234277769950392bc258cdd8172884528d8b9 (patch) | |
tree | 43ff7347ecb4dae0cb7821a53ab9702ffc011e2b | |
parent | d8949a395e09d6ef36eebebcb96ccdac641d5daa (diff) | |
download | chawan-b06234277769950392bc258cdd8172884528d8b9.tar.gz |
url: fix opaque host parsing, add has to auth case
* Opaque host parsing: it was not returning the output value. Also, special was not being passed to the host parser so in effect it wasn't even being used at all. * Authority case: it was checking for c without checking for has, that might cause an OOB exception.
-rw-r--r-- | src/types/url.nim | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/types/url.nim b/src/types/url.nim index 5c62134c..b3096224 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -252,6 +252,7 @@ func opaqueParseHost(input: string): Option[Host] = var o = "" for c in input: o.percentEncode(c, ControlPercentEncodeSet) + return some(Host(opaquehost: o)) func endsInNumber(input: string): bool = var parts = input.split('.') @@ -303,14 +304,14 @@ func domainToAscii*(domain: string, bestrict = false): Option[string] = else: return domain.tolower().some -func parseHost(input: string, isnotspecial = false): Option[Host] = +func parseHost(input: string, special: bool): Option[Host] = if input.len == 0: return if input[0] == '[': if input[^1] != ']': #TODO validation error return none(Host) return Host(ipv6: parseIpv6(input.substr(1, input.high - 1))).some - if isnotspecial: #TODO ?? + if not special: return opaqueParseHost(input) let domain = percentDecode(input) let asciiDomain = domain.domainToAscii() @@ -452,7 +453,7 @@ proc basicParseUrl*(input: string, base = none(URL), url: URL = URL(), state = RELATIVE_STATE dec pointer of PATH_OR_AUTHORITY_STATE: - if c == '/': + if has and c == '/': state = AUTHORITY_STATE else: state = PATH_STATE @@ -543,7 +544,7 @@ proc basicParseUrl*(input: string, base = none(URL), url: URL = URL(), if buffer == "": #TODO validation error return none(Url) - let host = parseHost(buffer) + let host = parseHost(buffer, url.is_special) if host.isnone: return none(Url) url.host = host @@ -557,7 +558,7 @@ proc basicParseUrl*(input: string, base = none(URL), url: URL = URL(), return none(Url) elif override and buffer == "" and (url.includes_credentials or url.port.issome): return - let host = parseHost(buffer) + let host = parseHost(buffer, url.is_special) if host.isnone: return none(Url) url.host = host @@ -644,7 +645,7 @@ proc basicParseUrl*(input: string, base = none(URL), url: URL = URL(), return state = PATH_START_STATE else: - var host = parseHost(buffer) + var host = parseHost(buffer, url.is_special) if host.isnone: return none(Url) if host.get.domain == "localhost": |