diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b60b61fda3..52aefd9b82 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -8,6 +8,7 @@ Changelog * Fix: Fix issue where invalid bulk action URLs would incorrectly trigger a server error (500) instead of a valid not found (404) (Ihor Marhitych) * Fix: Fix issue where bulk actions would not work for object IDs greater than 999 when `USE_THOUSAND_SEPARATOR` (Dennis McGregor) * Fix: Set cookie for sidebar collapsed state to "SameSite: lax" (LB (Ben Johnston)) + * Fix: Prevent error on creating automatic redirects for sites with non-standard ports (Matt Westcott) 2.16 (07.02.2022) diff --git a/docs/releases/2.16.1.rst b/docs/releases/2.16.1.rst index 777a96c86f..2367495f04 100644 --- a/docs/releases/2.16.1.rst +++ b/docs/releases/2.16.1.rst @@ -17,3 +17,4 @@ Bug fixes * Fix issue where invalid bulk action URLs would incorrectly trigger a server error (500) instead of a valid not found (404) (Ihor Marhitych) * Fix issue where bulk actions would not work for object IDs greater than 999 when ``USE_THOUSAND_SEPARATOR`` (Dennis McGregor) * Set cookie for sidebar collapsed state to "SameSite: lax" (LB (Ben Johnston)) + * Prevent error on creating automatic redirects for sites with non-standard ports (Matt Westcott) diff --git a/wagtail/core/tests/test_utils.py b/wagtail/core/tests/test_utils.py index 6cecf74329..4782c31162 100644 --- a/wagtail/core/tests/test_utils.py +++ b/wagtail/core/tests/test_utils.py @@ -5,11 +5,11 @@ from django.utils.text import slugify from django.utils.translation import _trans from django.utils.translation import gettext_lazy as _ -from wagtail.core.models import Page +from wagtail.core.models import Page, Site from wagtail.core.utils import ( accepts_kwarg, camelcase_to_underscore, cautious_slugify, find_available_slug, - get_content_languages, get_supported_content_language_variant, multigetattr, safe_snake_case, - string_to_ascii) + get_content_languages, get_dummy_request, get_supported_content_language_variant, multigetattr, + safe_snake_case, string_to_ascii) class TestCamelCaseToUnderscore(TestCase): @@ -354,3 +354,23 @@ class TestMultigetattr(TestCase): with self.assertRaises(SuspiciousOperation): multigetattr(self.thing, 'poke') self.assertFalse(self.thing.poke_was_called) + + +class TestGetDummyRequest(TestCase): + def test_standard_port(self): + site = Site.objects.first() + site.hostname = 'other.example.com' + site.port = 80 + site.save() + + request = get_dummy_request(site=site) + self.assertEqual(request.get_host(), 'other.example.com') + + def test_non_standard_port(self): + site = Site.objects.first() + site.hostname = 'other.example.com' + site.port = 8888 + site.save() + + request = get_dummy_request(site=site) + self.assertEqual(request.get_host(), 'other.example.com:8888') diff --git a/wagtail/core/utils.py b/wagtail/core/utils.py index 712cebbc68..e4236b381a 100644 --- a/wagtail/core/utils.py +++ b/wagtail/core/utils.py @@ -397,8 +397,6 @@ def get_dummy_request(path: str = "/", site: 'Site' = None) -> HttpRequest: SERVER_PORT = 80 if site: SERVER_NAME = site.hostname - if site.port not in [80, 443]: - SERVER_NAME += f":{site.port}" SERVER_PORT = site.port elif settings.ALLOWED_HOSTS == ["*"]: SERVER_NAME = "example.com"