From 136d8d9e5c9a2a0414e4934cc928bca23bfe944b Mon Sep 17 00:00:00 2001 From: bptato Date: Sun, 1 Oct 2023 17:44:48 +0200 Subject: Add w3m-cgi-compat option --- src/types/urimethodmap.nim | 4 ++++ src/types/url.nim | 43 ++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 21 deletions(-) (limited to 'src/types') diff --git a/src/types/urimethodmap.nim b/src/types/urimethodmap.nim index 6d57230b..f49162dd 100644 --- a/src/types/urimethodmap.nim +++ b/src/types/urimethodmap.nim @@ -61,8 +61,12 @@ proc parseURIMethodMap*(this: var URIMethodMap, s: string) = while i < line.len and line[i] in AsciiWhitespace: inc i var v = line.until(AsciiWhitespace, i) + # Basic w3m compatibility. + # If needed, w3m-cgi-compat covers more cases. if v.startsWith("file:/cgi-bin/"): v = "cgi-bin:" & v.substr("file:/cgi-bin/".len) + elif v.startsWith("file:///cgi-bin/"): + v = "cgi-bin:" & v.substr("file:///cgi-bin/".len) elif v.startsWith("/cgi-bin/"): v = "cgi-bin:" & v.substr("/cgi-bin/".len) this[k] = v diff --git a/src/types/url.nim b/src/types/url.nim index ab8c9e8b..562ec31b 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -351,8 +351,6 @@ proc basicParseURL*(input: string, base = none(URL), url: URL = URL(), i + 2 <= endi and input[i] in AsciiAlpha and input[i + 1] in {':', '|'} template is_normalized_windows_drive_letter(s: string): bool = s.len == 2 and s[0] in AsciiAlpha and s[1] == ':' - template is_windows_drive_letter(s: string): bool = - s.len == 2 and s[0] in AsciiAlpha and (s[1] == ':' or s[1] == '|') template is_double_dot_path_segment(s: string): bool = s == ".." or s.equalsIgnoreCase(".%2e") or s.equalsIgnoreCase("%2e.") or s.equalsIgnoreCase("%2e%2e") @@ -779,26 +777,29 @@ func serialize*(path: URLPath): string {.inline.} = result &= '/' result &= s -func serialize_unicode*(path: URLPath): string {.inline.} = - if path.opaque: - return percentDecode(path.s) - for s in path.ss: - 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] +when defined(windows) or defined(OS2) or defined(DOS): + func serialize_unicode_dos(path: URLPath): string = + 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 - while i < path.ss.len: - let s = path.ss[i] - result &= '\\' - result &= percentDecode(s) - inc i + func serialize_unicode*(path: URLPath): string = + return path.serialize_unicode_dos() +else: + func serialize_unicode*(path: URLPath): string = + if path.opaque: + return percentDecode(path.s) + for s in path.ss: + result &= '/' + result &= percentDecode(s) func serialize*(url: URL, excludefragment = false, excludepassword = false): string = -- cgit