aboutsummaryrefslogtreecommitdiffstats
path: root/src/types
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-10-01 17:44:48 +0200
committerbptato <nincsnevem662@gmail.com>2023-10-01 18:06:26 +0200
commit136d8d9e5c9a2a0414e4934cc928bca23bfe944b (patch)
treea35f3e30bc9839b612d7382a017c460fb335fd5b /src/types
parent478db794b90ebd205a6a191369581adbd440fd4e (diff)
downloadchawan-136d8d9e5c9a2a0414e4934cc928bca23bfe944b.tar.gz
Add w3m-cgi-compat option
Diffstat (limited to 'src/types')
-rw-r--r--src/types/urimethodmap.nim4
-rw-r--r--src/types/url.nim43
2 files changed, 26 insertions, 21 deletions
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 =