Skip to content

Commit

Permalink
fix(uri): fix trailing white spaces
Browse files Browse the repository at this point in the history
Fix trailing white spaces.
Makes cosmetic changes.

closes falconry#1872
  • Loading branch information
MinesJA committed Mar 7, 2021
1 parent d1d09e0 commit 8cc64b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions falcon/response.py
Expand Up @@ -675,7 +675,7 @@ def delete_header(self, name):
# NOTE(kgriffs): normalize name by lowercasing it
name = name.lower()

if name == 'set-cookie':
if name == 'set-cookie':
raise HeaderNotSupported('This method cannot be used to remove cookies')

self._headers.pop(name, None)
Expand Down Expand Up @@ -769,7 +769,7 @@ def set_headers(self, headers):
value = str(value)

name = name.lower()
if name == 'set-cookie':
if name == 'set-cookie':
raise HeaderNotSupported('This method cannot be used to set cookies')

_headers[name] = value
Expand Down
6 changes: 3 additions & 3 deletions falcon/util/uri.py
Expand Up @@ -82,9 +82,9 @@ def encoder(uri, check_is_escaped=False):
if check_is_escaped and not uri.rstrip(allowed_chars_plus_percent):
# NOTE(kgriffs): There's a good chance the string has already
# been escaped. Do one more check to increase our certainty.
# NOTE(minesja): Per issue #1872, there's only certain situations
# in which we should check again (ex. location, content_location,
# append_link).In all other cases we should allow characters that
# NOTE(minesja): Per issue #1872, there's only certain situations
# in which we should check again (ex. location, content_location,
# append_link).In all other cases we should allow characters that
# could appear escaped to still be encoded (ex. '%' would be encoded
# as '%25).
tokens = uri.split('%')
Expand Down
9 changes: 4 additions & 5 deletions tests/test_utils.py
Expand Up @@ -226,12 +226,11 @@ def test_uri_encode(self):

# NOTE(minesja): Addresses #1872
assert uri.encode('%26') == '%2526'
assert uri.decode(uri.encode('%26') == '%26')
assert uri.decode(uri.encode('%26')) == '%26'

def test_uri_encode_double(self):
# NOTE(minesja): check_is_escaped added to address maintain
# ignoring escaped values (addresses #68) while also
# addressing #1872 which should escape all values by default
# NOTE(minesja): check_is_escaped added to allow option to
# retain behavior of ignoring already escaped values (#68)
url = 'http://example.com/v1/fiz bit/messages'
expected = 'http://example.com/v1/fiz%20bit/messages'
assert uri.encode(uri.encode(url), check_is_escaped=True) == expected
Expand Down Expand Up @@ -268,7 +267,7 @@ def test_uri_encode_value(self):
assert uri.encode_value('\u00e7\u20ac') == '%C3%A7%E2%82%AC'
assert uri.encode_value('ab/cd') == 'ab%2Fcd'
assert uri.encode_value('ab+cd=42,9') == 'ab%2Bcd%3D42%2C9'

# NOTE(minesja): Addresses #1872
assert uri.encode_value('%26') == '%2526'
assert uri.decode(uri.encode_value('%26')) == '%26'
Expand Down

0 comments on commit 8cc64b5

Please sign in to comment.