aboutsummaryrefslogtreecommitdiffstats
path: root/src/types
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-10-01 18:19:06 +0200
committerbptato <nincsnevem662@gmail.com>2023-10-01 18:19:06 +0200
commitedf0d60f81407f8fa0de9d05df0f15ee98cabc70 (patch)
treeb4ad0a954155b1ccf535a4f9dfef85cb38ab98b8 /src/types
parent136d8d9e5c9a2a0414e4934cc928bca23bfe944b (diff)
downloadchawan-edf0d60f81407f8fa0de9d05df0f15ee98cabc70.tar.gz
urimethodmap fixes
Diffstat (limited to 'src/types')
-rw-r--r--src/types/urimethodmap.nim13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/types/urimethodmap.nim b/src/types/urimethodmap.nim
index f49162dd..f2015a70 100644
--- a/src/types/urimethodmap.nim
+++ b/src/types/urimethodmap.nim
@@ -30,9 +30,6 @@ func rewriteURL(pattern, surl: string): string =
if was_perc:
result &= '%'
-proc `[]=`*(this: var URIMethodMap, k, v: string) =
- this.map[k] = v
-
type URIMethodMapResult* = enum
URI_RESULT_NOT_FOUND, URI_RESULT_SUCCESS, URI_RESULT_WRONG_URL
@@ -53,11 +50,13 @@ proc parseURIMethodMap*(this: var URIMethodMap, s: string) =
continue # comments
var k = ""
var i = 0
- while i < line.len and line[i] != ':':
- k &= line[i].toLowerAscii()
+ while i < line.len and line[i] notin AsciiWhitespace + {':'}:
+ k &= line[i].tolower()
inc i
- if i >= line.len:
+ if i >= line.len or line[i] != ':':
continue # invalid
+ k &= ':'
+ inc i # skip colon
while i < line.len and line[i] in AsciiWhitespace:
inc i
var v = line.until(AsciiWhitespace, i)
@@ -69,4 +68,4 @@ proc parseURIMethodMap*(this: var URIMethodMap, s: string) =
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
+ discard this.map.hasKeyOrPut(k, v)