python3-django: fix ipv6 validation
PATCH 1/2 python3-django: fix ipv6 validation
This patch is only for python3-django_3.2.25.
The URL validator didn't detect invalid IPv6 addresses, treating them as correct ones, making a testcase fail. (Also, according to the comment, it could also crash in some cases, though I haven't encountered that)
This backported patch mitigates this behavior.
--- ...d-URLValidator-crash-in-some-edge-ca.patch | 56 +++++++++++++++++++ .../python/python3-django_3.2.25.bb | 1 + 2 files changed, 57 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-django-3.2.25/0001-Fixed-33367-Fixed-URLValidator-crash-in-some-edge-ca.patch
meta-python/recipes-devtools/python/python3-django-3.2.25/0001-Fixed-33367-Fixed-URLValidator-crash-in-some-edge-ca.patch new file +56 -0
@@ -0,0 +1,56 @@ +From 065b10e2757af671f3e64f0c8714e6f2e4eca727 Mon Sep 17 00:00:00 2001 +From: Gyorgy Sarvari <[email protected]> +Date: Wed, 15 Dec 2021 11:55:19 -0300 +Subject: [PATCH] Fixed #33367 -- Fixed URLValidator crash in some edge cases. + +From: mendespedro <[email protected]> + +Upstream-Status: Backport [https://github.com/django/django/commit/e8b4feddc34ffe5759ec21da8fa027e86e653f1c] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + django/core/validators.py | 14 ++++++++------ + 1 file changed, 8 insertions(+), 6 deletions(-) + +diff --git a/django/core/validators.py b/django/core/validators.py +index 94cc3bf..03cd9b8 100644 +--- a/django/core/validators.py ++++ b/django/core/validators.py +@@ -111,15 +111,16 @@ class URLValidator(RegexValidator): + raise ValidationError(self.message, code=self.code, params={'value': value}) + + # Then check full URL ++ try: ++ splitted_url = urlsplit(value) ++ except ValueError: ++ raise ValidationError(self.message, code=self.code, params={'value': value}) + try: + super().__call__(value) + except ValidationError as e: + # Trivial case failed. Try for possible IDN domain + if value: +- try: +- scheme, netloc, path, query, fragment = urlsplit(value) +- except ValueError: # for example, "Invalid IPv6 URL" +- raise ValidationError(self.message, code=self.code, params={'value': value}) ++ scheme, netloc, path, query, fragment = splitted_url + try: + netloc = punycode(netloc) # IDN -> ACE + except UnicodeError: # invalid domain part +@@ -130,7 +131,7 @@ class URLValidator(RegexValidator): + raise + else: + # Now verify IPv6 in the netloc part +- host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', urlsplit(value).netloc) ++ host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', splitted_url.netloc) + if host_match: + potential_ip = host_match[1] + try: +@@ -142,7 +143,7 @@ class URLValidator(RegexValidator): + # section 3.1. It's defined to be 255 bytes or less, but this includes + # one byte for the length of the name and one byte for the trailing dot + # that's used to indicate absolute names in DNS. +- if len(urlsplit(value).hostname) > 253: ++ if splitted_url.hostname is None or len(splitted_url.hostname) > 253: + raise ValidationError(self.message, code=self.code, params={'value': value}) + +
meta-python/recipes-devtools/python/python3-django_3.2.25.bb +1 -0
@@ -15,6 +15,7 @@ SRC_URI += "\ file://CVE-2024-41991.patch \ file://CVE-2024-53907.patch \ file://CVE-2025-32873.patch \ + file://0001-Fixed-33367-Fixed-URLValidator-crash-in-some-edge-ca.patch \ " # Set DEFAULT_PREFERENCE so that the LTS version of django is built by
PATCH 2/2 python3-django: fix tests
These patches are for python3-django_3.2.25
These patches only touch the tests folder, which is normally not installed.
Most of these changes are backported patches, that adapt tests to modern(er) Python environment than they were written for, and some other just fix a bug in the tests that were always present.
0001-Fix-tag_strip-tests.patch: The html parser's behavior in Python has changed, making this testcase fail. This is a partial backport of the patch, which handles only the Python version that is shipped with oe-core (The original patch handles both old and new versions)
0001-Fixed-test_utils.tests.HTMLEqualTests.test_parsing_e.patch: this backported patch makes a test-verification conform to html5 standard. Previously the test failed.
--- .../0001-Fix-tag_strip-tests.patch | 37 +++++++++++++++++++ ....tests.HTMLEqualTests.test_parsing_e.patch | 32 ++++++++++++++++ .../python/python3-django_3.2.25.bb | 2 + 3 files changed, 71 insertions(+) create mode 100644 meta-python/recipes-devtools/python/python3-django-3.2.25/0001-Fix-tag_strip-tests.patch create mode 100644 meta-python/recipes-devtools/python/python3-django-3.2.25/0001-Fixed-test_utils.tests.HTMLEqualTests.test_parsing_e.patch
meta-python/recipes-devtools/python/python3-django-3.2.25/0001-Fix-tag_strip-tests.patch new file +37 -0
@@ -0,0 +1,37 @@ +From bd3ffbbacceef7fabd3135ca90eba1397e2b5901 Mon Sep 17 00:00:00 2001 +From: Your Name <[email protected]> +Date: Tue, 13 Jan 2026 20:07:35 +0000 +Subject: [PATCH] Fix tag_strip tests + +Python's htmlparser behavior changed between python versions, and +the tests expect incorrect result due to this. + +This patch is a partial backport, to use only the results that are +valid for the OE Python version. + +Upstream-Status: Backport [https://github.com/django/django/commit/2980627502c84a9fd09272e1349dc574a2ff1fb1] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + tests/utils_tests/test_html.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py +index 86f5562..71757ad 100644 +--- a/tests/utils_tests/test_html.py ++++ b/tests/utils_tests/test_html.py +@@ -91,10 +91,10 @@ class TestUtilsHtml(SimpleTestCase): + ('&gotcha&#;<>', '&gotcha&#;<>'), + ('<sc<!-- -->ript>test<<!-- -->/script>', 'ript>test'), + ('<script>alert()</script>&h', 'alert()h'), +- ('><!' + ('&' * 16000) + 'D', '><!' + ('&' * 16000) + 'D'), ++ ('><!' + ('&' * 16000) + 'D', '>'), + ('X<<<<br>br>br>br>X', 'XX'), + ("<" * 50 + "a>" * 50, ""), +- (">" + "<a" * 500 + "a", ">" + "<a" * 500 + "a"), ++ (">" + "<a" * 500 + "a", ">"), + ("<a" * 49 + "a" * 951, "<a" * 49 + "a" * 951), + ("<" + "a" * 1_002, "<" + "a" * 1_002), + ) +-- +2.39.5 +
meta-python/recipes-devtools/python/python3-django-3.2.25/0001-Fixed-test_utils.tests.HTMLEqualTests.test_parsing_e.patch new file +32 -0
@@ -0,0 +1,32 @@ +From 744927154e6748db08f5232de78ee0d4a8be61a5 Mon Sep 17 00:00:00 2001 +From: Gyorgy Sarvari <[email protected]> +Date: Mon, 21 Jul 2025 15:23:32 -0300 +Subject: [PATCH] Fixed test_utils.tests.HTMLEqualTests.test_parsing_errors + following Python's HTMLParser fixed parsing. + +From: Natalia <[email protected]> + +Further details about Python changes can be found in: +https://github.com/python/cpython/commit/0243f97cbadec8d985e63b1daec5d1cbc850cae3. + +Thank you Clifford Gama for the thorough review! + +Upstream-Status: Backport [https://github.com/django/django/commit/e4515dad7a6d953c0bd2414127ba36e1446ff41a] +Signed-off-by: Gyorgy Sarvari <[email protected]> +--- + tests/test_utils/tests.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py +index a1a113a..d1a1e35 100644 +--- a/tests/test_utils/tests.py ++++ b/tests/test_utils/tests.py +@@ -848,7 +848,7 @@ class HTMLEqualTests(SimpleTestCase): + "('Unexpected end tag `div` (Line 1, Column 6)', (1, 6))" + ) + with self.assertRaisesMessage(AssertionError, error_msg): +- self.assertHTMLEqual('< div></ div>', '<div></div>') ++ self.assertHTMLEqual('< div></div>', '<div></div>') + with self.assertRaises(HTMLParseError): + parse_html('</p>') +
meta-python/recipes-devtools/python/python3-django_3.2.25.bb +2 -0
@@ -16,6 +16,8 @@ SRC_URI += "\ file://CVE-2024-53907.patch \ file://CVE-2025-32873.patch \ file://0001-Fixed-33367-Fixed-URLValidator-crash-in-some-edge-ca.patch \ + file://0001-Fix-tag_strip-tests.patch \ + file://0001-Fixed-test_utils.tests.HTMLEqualTests.test_parsing_e.patch \ " # Set DEFAULT_PREFERENCE so that the LTS version of django is built by