Skip to content

Commit

Permalink
show warning instead of error when passing bytes to iri_to_uri (#2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Jun 6, 2023
2 parents d70b37d + dc9e73b commit 1892c10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Unreleased
- The debugger escapes the exception message in the page title. :pr:`2719`
- When binding ``routing.Map``, a long IDNA ``server_name`` with a port does not fail
encoding. :issue:`2700`
- ``iri_to_uri`` shows a deprecation warning instead of an error when passing bytes.
:issue:`2708`


Version 2.3.4
Expand Down
20 changes: 10 additions & 10 deletions src/werkzeug/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,16 @@ def iri_to_uri(
.. versionadded:: 0.6
"""
if charset is not None:
warnings.warn(
"The 'charset' parameter is deprecated and will be removed"
" in Werkzeug 3.0.",
DeprecationWarning,
stacklevel=2,
)
else:
charset = "utf-8"

if isinstance(iri, tuple):
warnings.warn(
"Passing a tuple is deprecated and will not be supported in Werkzeug 3.0.",
Expand All @@ -982,16 +992,6 @@ def iri_to_uri(
)
iri = iri.decode(charset)

if charset is not None:
warnings.warn(
"The 'charset' parameter is deprecated and will be removed"
" in Werkzeug 3.0.",
DeprecationWarning,
stacklevel=2,
)
else:
charset = "utf-8"

if errors is not None:
warnings.warn(
"The 'errors' parameter is deprecated and will be removed in Werkzeug 3.0.",
Expand Down
3 changes: 3 additions & 0 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ def test_iri_support():
with pytest.deprecated_call():
assert urls.uri_to_iri(b"/foo") == "/foo"

with pytest.deprecated_call():
assert urls.iri_to_uri(b"/foo") == "/foo"

assert urls.iri_to_uri("/foo") == "/foo"

assert (
Expand Down

0 comments on commit 1892c10

Please sign in to comment.