From 514e6099737b69edf58ec77001321798b65cb4ab Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 4 May 2024 23:07:35 +0100 Subject: [PATCH] Change minify-html details to be more spec compliant --- website/common/middleware.py | 9 +++++++++ website/search/tests.py | 2 +- website/settings.py | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 website/common/middleware.py diff --git a/website/common/middleware.py b/website/common/middleware.py new file mode 100644 index 0000000..cb79f93 --- /dev/null +++ b/website/common/middleware.py @@ -0,0 +1,9 @@ +from django_minify_html.middleware import MinifyHtmlMiddleware + + +class CustomMinifyHtmlMiddleware(MinifyHtmlMiddleware): + minify_args = { + "do_not_minify_doctype": True, + "ensure_spec_compliant_unquoted_attribute_values": True, + "keep_spaces_between_attributes": True, + } diff --git a/website/search/tests.py b/website/search/tests.py index 15c474c..b6acbbb 100644 --- a/website/search/tests.py +++ b/website/search/tests.py @@ -38,7 +38,7 @@ class SearchPageTestCase(TestCase): self.assertEqual(search_input.attrs["name"], "q") self.assertEqual(search_input.attrs["hx-get"], "results/") - self.assertEqual(search_input.attrs.get("value", ""), "") + self.assertNotIn("value", search_input.attrs) # Because of minify-html self.assertEqual(len(soup.select(search_input.attrs["hx-target"])), 1) self.assertEqual(len(soup.select(search_input.attrs["hx-indicator"])), 2) diff --git a/website/settings.py b/website/settings.py index e424730..d36b665 100644 --- a/website/settings.py +++ b/website/settings.py @@ -100,7 +100,7 @@ MIDDLEWARE = [ "corsheaders.middleware.CorsMiddleware", "enforce_host.EnforceHostMiddleware", "whitenoise.middleware.WhiteNoiseMiddleware", - "django_minify_html.middleware.MinifyHtmlMiddleware", + "website.common.middleware.CustomMinifyHtmlMiddleware", "django.middleware.common.CommonMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.csrf.CsrfViewMiddleware",