Skip to content

Commit

Permalink
Merge pull request #358 from KyleKaniecki/develop
Browse files Browse the repository at this point in the history
Fix _cast_urlstr unquoting
  • Loading branch information
sergeyklay committed Jan 2, 2022
2 parents 509cf77 + 3ea5d69 commit 0e9eba6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from urllib.parse import (
parse_qs,
ParseResult,
unquote,
unquote_plus,
urlparse,
urlunparse,
Expand Down Expand Up @@ -61,7 +62,7 @@ def _cast_int(v):


def _cast_urlstr(v):
return unquote_plus(v) if isinstance(v, str) else v
return unquote(v) if isinstance(v, str) else v


class NoValue:
Expand Down
19 changes: 18 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# the LICENSE.txt file that was distributed with this source code.

import pytest
from environ.environ import _cast
from environ.environ import _cast, _cast_urlstr


@pytest.mark.parametrize(
Expand All @@ -20,3 +20,20 @@ def test_cast(literal):
See https://github.com/joke2k/django-environ/issues/200 for details."""
assert _cast(literal) == literal

@pytest.mark.parametrize(
"quoted_url_str,expected_unquoted_str",
[
("Le-%7BFsIaYnaQw%7Da2B%2F%5BV8bS+", "Le-{FsIaYnaQw}a2B/[V8bS+"),
("my_test-string+", "my_test-string+"),
("my%20test%20string+", "my test string+")
]
)
def test_cast_urlstr(quoted_url_str, expected_unquoted_str):
"""Make sure that a url str that contains plus sign literals does not get unquoted incorrectly
Plus signs should not be converted to spaces, since spaces are encoded with %20 in URIs
see https://github.com/joke2k/django-environ/issues/357 for details.
related to https://github.com/joke2k/django-environ/pull/69"""

assert _cast_urlstr(quoted_url_str) == expected_unquoted_str

0 comments on commit 0e9eba6

Please sign in to comment.