Skip to content

Commit cc6fc7e

Browse files
authored
Querystring parsing (#118)
1 parent c540c4c commit cc6fc7e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

jinja2cli/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def _parse_qs(data):
165165
"""
166166
dict_ = {}
167167
for k, v in urlparse.parse_qs(data).items():
168-
v = map(lambda x: x.strip(), v)
168+
v = list(map(lambda x: x.strip(), v))
169169
v = v[0] if len(v) == 1 else v
170170
if "." in k:
171171
pieces = k.split(".")

tests/test_parse_qs.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
from jinja2cli import cli
4+
5+
QS_PARSER_FN, QS_EXCEPT_EXC, QS_RAISE_EXC = cli.get_format("querystring")
6+
7+
8+
@pytest.mark.parametrize(
9+
("qs", "qs_data"),
10+
[
11+
("", dict()),
12+
("foo=", dict()),
13+
("foo=bar", dict(foo="bar")),
14+
("foo=bar&ham=spam", dict(foo="bar", ham="spam")),
15+
("foo.bar=ham&ham.spam=eggs", dict(foo=dict(bar="ham"), ham=dict(spam="eggs"))),
16+
("foo=bar%20ham%20spam", dict(foo="bar ham spam")),
17+
("foo=bar%2Eham%2Espam", dict(foo="bar.ham.spam")),
18+
],
19+
)
20+
def test_parse_qs(qs, qs_data):
21+
assert QS_PARSER_FN(qs) == qs_data

0 commit comments

Comments
 (0)