follow #15860 clean cgi module (#16487)

* follow #15860  clean cgi module

* follow #15860  clean cgi module
This commit is contained in:
flywind 2020-12-27 12:46:21 -06:00 • committed by GitHub
commit e718a4a058
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 77 deletions

View file

@ -1,8 +1,4 @@
discard """
output: "works"
"""
import cgi, strtabs
import std/[cgi, strtabs]
proc handleRequest(query: string): StringTableRef =
iterator foo(): StringTableRef {.closure.} =
@ -26,4 +22,3 @@ proc main =
quit "but now a leak"
main()
echo "works"

View file

@ -1,25 +1,10 @@
discard """
output: '''
import std/unittest
import std/[cgi, strtabs, sugar]
[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")
'''
"""
import unittest
import cgi, strtabs
suite "Test cgi module":
block: # Test cgi module
const queryString = "foo=bar&фу=бар&checked=✓&list=1,2,3&with_space=text%20with%20space"
test "test query parsing with readData":
block: # test query parsing with readData
let parsedQuery = readData(queryString)
check parsedQuery["foo"] == "bar"
@ -34,5 +19,8 @@ suite "Test cgi module":
# 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
doAssert collect(for pair in decodeData(queryString): pair) ==
@[("a", "1"), ("b", "0"), ("c", "3"),
("d", ""),("e", ""), ("a", "5"), ("a", "t e x t"),
("e", "http://w3schools.com/my test.asp?name=ståle&car=saab")
]