Skip to content

Commit

Permalink
Keep empty query parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
sopoforic authored and karlicoss committed Mar 5, 2022
1 parent 90ba0d1 commit f8b8bd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/promnesia/cannon.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def transform_split(split: SplitResult):
netloc = canonify_domain(split.netloc)

path = split.path
qparts = parse_qsl(split.query)
qparts = parse_qsl(split.query, keep_blank_values=True)

fragment = split.fragment

Expand Down Expand Up @@ -319,7 +319,7 @@ def iter_rules():
to = to + ('', )

(netloc, path, qq) = [t.format(**gd) for t in to]
qparts.extend(parse_qsl(qq)) # TODO hacky..
qparts.extend(parse_qsl(qq, keep_blank_values=True)) # TODO hacky..
# TODO eh, qparts should really be a map or something...
break

Expand Down
8 changes: 8 additions & 0 deletions tests/cannon.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,11 @@ def test_error():
with pytest.raises(CanonifyException):
# borrowed from https://bugs.mageia.org/show_bug.cgi?id=24640#c7
canonify('https://example.com\uFF03@bing.com')

@pytest.mark.parametrize("url,expected", [
('https://news.ycombinator.com/item?id=', 'news.ycombinator.com/item?id='),
('https://www.youtube.com/watch?v=hvoQiF0kBI8&list&index=2',
'youtube.com/watch?v=hvoQiF0kBI8&list='),
])
def test_empty_query_parameter(url, expected):
assert canonify(url) == expected

0 comments on commit f8b8bd7

Please sign in to comment.