summaryrefslogtreecommitdiff
path: root/dev-python/werkzeug/files/werkzeug-2.3.4-iri-bytes.patch
blob: 1e06b0621cdd529584fa4affff1bab3a0843ad2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From 3ba0fd5c52c9943c492ce098693bf9e651942fe5 Mon Sep 17 00:00:00 2001
From: midchildan <git@midchildan.org>
Date: Sat, 27 May 2023 01:03:02 +0900
Subject: [PATCH] fix: iri_to_uri fails when the argument is a bytestring

This was caused by the 'charset' variable being used before it was ready.
---
 CHANGES.rst          |  4 ++++
 src/werkzeug/urls.py | 20 ++++++++++----------
 tests/test_urls.py   |  3 +++
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/werkzeug/urls.py b/src/werkzeug/urls.py
index 89ef21943..f5760eb4c 100644
--- a/src/werkzeug/urls.py
+++ b/src/werkzeug/urls.py
@@ -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.",
@@ -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.",
diff --git a/tests/test_urls.py b/tests/test_urls.py
index 56bca8e94..765d42546 100644
--- a/tests/test_urls.py
+++ b/tests/test_urls.py
@@ -231,6 +231,9 @@ def test_iri_support():
 
     assert urls.iri_to_uri("/foo") == "/foo"
 
+    with pytest.deprecated_call():
+        assert urls.iri_to_uri(b"/foo") == "/foo"
+
     assert (
         urls.iri_to_uri("http://föö.com:8080/bam/baz")
         == "http://xn--f-1gaa.com:8080/bam/baz"