Skip to content

Commit 4eda39d

Browse files
authored
Add additional coverage for the unquoter (#1498)
1 parent 194ab70 commit 4eda39d

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

CHANGES/1498.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1496.misc.rst

tests/test_quoting.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,14 @@ def test_unquote_plus_to_space_unsafe(unquoter: type[_Unquoter]) -> None:
457457
assert unquoter(unsafe="+", qs=True)("a+b") == "a+b"
458458

459459

460+
def test_unquote_multiple_unsafe(unquoter: type[_Unquoter]) -> None:
461+
assert unquoter(unsafe="!@#$")("a!@#$b") == "a%21%40%23%24b"
462+
463+
464+
def test_unquote_explict_empty_unsafe(unquoter: type[_Unquoter]) -> None:
465+
assert unquoter(unsafe="")("a!@#$b") == "a!@#$b"
466+
467+
460468
def test_quote_qs_with_colon(quoter: type[_Quoter]) -> None:
461469
s = quoter(safe="=+&?/:@", qs=True)("next=http%3A//example.com/")
462470
assert s == "next=http://example.com/"

yarl/_quoting_c.pyx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ cdef class _Unquoter:
310310
cdef str _ignore
311311
cdef bint _has_ignore
312312
cdef str _unsafe
313+
cdef bytes _unsafe_bytes
313314
cdef Py_ssize_t _unsafe_bytes_len
314315
cdef const unsigned char * _unsafe_bytes_char
315316
cdef bint _qs
@@ -322,9 +323,9 @@ cdef class _Unquoter:
322323
self._has_ignore = bool(self._ignore)
323324
self._unsafe = unsafe
324325
# unsafe may only be extended ascii characters (0-255)
325-
unsafe_bytes = self._unsafe.encode('ascii')
326-
self._unsafe_bytes_len = len(unsafe_bytes)
327-
self._unsafe_bytes_char = unsafe_bytes
326+
self._unsafe_bytes = self._unsafe.encode('ascii')
327+
self._unsafe_bytes_len = len(self._unsafe_bytes)
328+
self._unsafe_bytes_char = self._unsafe_bytes
328329
self._qs = qs
329330
self._plus = plus
330331
self._quoter = _Quoter()

0 commit comments

Comments
 (0)