Skip to content

Commit 4a96c84

Browse files
committed
don't unquote percent-encoded + in to_iri since it may be ambiguous
1 parent b8c9152 commit 4a96c84

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/hyperlink/_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _make_quote_map(safe_chars):
225225
_QUERY_KEY_QUOTE_MAP = _make_quote_map(_QUERY_KEY_SAFE)
226226
_QUERY_KEY_DECODE_MAP = _make_decode_map(_QUERY_KEY_DELIMS)
227227
_QUERY_VALUE_QUOTE_MAP = _make_quote_map(_QUERY_VALUE_SAFE)
228-
_QUERY_VALUE_DECODE_MAP = _make_decode_map(_QUERY_VALUE_DELIMS)
228+
_QUERY_VALUE_DECODE_MAP = _make_decode_map(_QUERY_VALUE_DELIMS | set("+"))
229229
_FRAGMENT_QUOTE_MAP = _make_quote_map(_FRAGMENT_SAFE)
230230
_FRAGMENT_DECODE_MAP = _make_decode_map(_FRAGMENT_DELIMS)
231231
_UNRESERVED_QUOTE_MAP = _make_quote_map(_UNRESERVED_CHARS)

src/hyperlink/test/test_decoded_url.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ def test_durl_basic(self):
3636
assert durl.user == "user"
3737
assert durl.userinfo == ("user", "\0\0\0\0")
3838

39+
def test_roundtrip_iri_parameter_values(self):
40+
"""
41+
.to_iri() should never modify the application-level data of a query
42+
parameter.
43+
"""
44+
# type: () -> None
45+
for value in ["hello", "goodbye", "+", "/", ":", "?"]:
46+
self.assertEqual(
47+
DecodedURL(DecodedURL().set("test", value).to_iri()).get(
48+
"test"
49+
),
50+
[value],
51+
)
52+
53+
def test_roundtrip_uri_parameter_values(self):
54+
"""
55+
.to_uri() should never modify the application-level data of a query
56+
parameter.
57+
"""
58+
# type: () -> None
59+
for value in ["hello", "goodbye", "+", "/", ":", "?"]:
60+
self.assertEqual(
61+
DecodedURL(DecodedURL().set("test", value).to_uri()).get(
62+
"test"
63+
),
64+
[value],
65+
)
66+
3967
def test_passthroughs(self):
4068
# type: () -> None
4169

0 commit comments

Comments
 (0)