diff options
author | bptato <nincsnevem662@gmail.com> | 2022-01-25 16:40:55 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-01-25 16:40:55 +0100 |
commit | 8fb2b9a0a505a9051bac04ab0163b20db95b86fb (patch) | |
tree | d291a0da551a2682d3b6fef06daa81b173521702 /src/types | |
parent | 16fa06be2a19780759195251c4a1f242ee0f8d10 (diff) | |
download | chawan-8fb2b9a0a505a9051bac04ab0163b20db95b86fb.tar.gz |
Fix some path bugs and misc. warnings
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/url.nim | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/types/url.nim b/src/types/url.nim index 00a5fd51..c8c7085e 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -323,6 +323,7 @@ proc append(path: var UrlPath, s: string) = path.ss.add(s) template includes_credentials(url: Url): bool = url.username != "" or url.password != "" +template is_windows_drive_letter(s: string): bool = s.len == 2 and s[0] in Letters and (s[1] == ':' or s[1] == '|') #TODO encoding proc basicParseUrl*(input: string, base = none(Url), url: var Url = Url(), override: bool = false): Option[Url] = @@ -606,7 +607,7 @@ proc basicParseUrl*(input: string, base = none(Url), url: var Url = Url(), overr state = PATH_STATE dec pointer of FILE_HOST_STATE: - if (not has or c in {'/', '?', '#'}): + if (not has or c in {'/', '\\', '?', '#'}): dec pointer if not override and buffer.is_windows_drive_letter: #TODO validation error @@ -801,6 +802,20 @@ func serialize_unicode*(path: UrlPath): string {.inline.} = result &= '/' result &= percentDecode(s) +func serialize_unicode_dos*(path: UrlPath): string {.inline.} = + if path.opaque: + return percentDecode(path.s) + var i = 0 + if i < path.ss.len: + if path.ss[i].is_windows_drive_letter: + result &= path.ss[i] + inc i + while i < path.ss.len: + let s = path.ss[i] + result &= '\\' + result &= percentDecode(s) + inc i + func serialize*(url: Url, excludefragment = false): string = result = url.scheme & ':' if url.host.issome: |