This commit is contained in:
Andreas Rumpf
2020-09-20 01:07:13 +02:00
committed by GitHub
parent a15d77df7e
commit ebb632ccba
2 changed files with 17 additions and 3 deletions

View File

@@ -105,10 +105,10 @@ iterator decodeData*(data: string): tuple[key, value: TaintedString] =
while i < data.len:
setLen(name, 0) # reuse memory
i = parseData(data, i, name)
if i >= data.len or data[i] != '=': cgiError("'=' expected")
inc(i) # skip '='
setLen(value, 0) # reuse memory
i = parseData(data, i, value)
if i < data.len and data[i] == '=':
inc(i) # skip '='
i = parseData(data, i, value)
yield (name.TaintedString, value.TaintedString)
if i < data.len:
if data[i] == '&': inc(i)

View File

@@ -1,6 +1,14 @@
discard """
output: '''
[Suite] Test cgi module
(key: "a", value: "1")
(key: "b", value: "0")
(key: "c", value: "3")
(key: "d", value: "")
(key: "e", value: "")
(key: "a", value: "5")
(key: "a", value: "t e x t")
(key: "e", value: "http://w3schools.com/my test.asp?name=ståle&car=saab")
'''
"""
@@ -21,3 +29,9 @@ suite "Test cgi module":
expect KeyError:
discard parsedQuery["not_existing_key"]
# bug #15369
let queryString = "a=1&b=0&c=3&d&e&a=5&a=t%20e%20x%20t&e=http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab"
for pair in decodeData(queryString):
echo pair