more fixes for the new string behaviour

This commit is contained in:
Andreas Rumpf 2018-04-30 08:53:31 +02:00
commit 5758ebf02c
3 changed files with 12 additions and 14 deletions

View file

@ -107,7 +107,7 @@ proc executeCgi(server: var TServer, client: Socket, path, query: string,
dataAvail = recvLine(client, buf) dataAvail = recvLine(client, buf)
if buf.len == 0: if buf.len == 0:
break break
var L = toLower(buf) var L = toLowerAscii(buf)
if L.startsWith("content-length:"): if L.startsWith("content-length:"):
var i = len("content-length:") var i = len("content-length:")
while L[i] in Whitespace: inc(i) while L[i] in Whitespace: inc(i)
@ -205,7 +205,7 @@ proc acceptRequest(server: var TServer, client: Socket) =
client.close() client.close()
else: else:
when defined(Windows): when defined(Windows):
var ext = splitFile(path).ext.toLower var ext = splitFile(path).ext.toLowerAscii
if ext == ".exe" or ext == ".cgi": if ext == ".exe" or ext == ".cgi":
# XXX: extract interpreter information here? # XXX: extract interpreter information here?
cgi = true cgi = true

View file

@ -1060,18 +1060,17 @@ proc parseCmdLine*(c: string): seq[string] {.
while true: while true:
setLen(a, 0) setLen(a, 0)
# eat all delimiting whitespace # eat all delimiting whitespace
while c[i] == ' ' or c[i] == '\t' or c[i] == '\l' or c[i] == '\r' : inc(i) while i < c.len and c[i] in {' ', '\t', '\l', '\r'}: inc(i)
if i >= c.len: break
when defined(windows): when defined(windows):
# parse a single argument according to the above rules: # parse a single argument according to the above rules:
if c[i] == '\0': break
var inQuote = false var inQuote = false
while true: while i < c.len:
case c[i] case c[i]
of '\0': break
of '\\': of '\\':
var j = i var j = i
while c[j] == '\\': inc(j) while j < c.len and c[j] == '\\': inc(j)
if c[j] == '"': if j < c.len and c[j] == '"':
for k in 1..(j-i) div 2: a.add('\\') for k in 1..(j-i) div 2: a.add('\\')
if (j-i) mod 2 == 0: if (j-i) mod 2 == 0:
i = j i = j
@ -1084,7 +1083,7 @@ proc parseCmdLine*(c: string): seq[string] {.
of '"': of '"':
inc(i) inc(i)
if not inQuote: inQuote = true if not inQuote: inQuote = true
elif c[i] == '"': elif i < c.len and c[i] == '"':
a.add(c[i]) a.add(c[i])
inc(i) inc(i)
else: else:
@ -1102,13 +1101,12 @@ proc parseCmdLine*(c: string): seq[string] {.
of '\'', '\"': of '\'', '\"':
var delim = c[i] var delim = c[i]
inc(i) # skip ' or " inc(i) # skip ' or "
while c[i] != '\0' and c[i] != delim: while i < c.len and c[i] != delim:
add a, c[i] add a, c[i]
inc(i) inc(i)
if c[i] != '\0': inc(i) if i < c.len: inc(i)
of '\0': break
else: else:
while c[i] > ' ': while i < c.len and c[i] > ' ':
add(a, c[i]) add(a, c[i])
inc(i) inc(i)
add(result, a) add(result, a)

View file

@ -606,7 +606,7 @@ proc rawMatch*(s: string, p: Peg, start: int, c: var Captures): int {.
a, b: Rune a, b: Rune
result = start result = start
while i < len(p.term): while i < len(p.term):
if i >= s.len: if result >= s.len:
result = -1 result = -1
break break
fastRuneAt(p.term, i, a) fastRuneAt(p.term, i, a)