From bf9212d0705b13bf34b18f5d382f3c0591cd54af Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 14 Jun 2024 10:29:28 +0100 Subject: [PATCH 1/3] Drop HTML line breaks on long headers --- rest_framework/templates/rest_framework/base.html | 2 +- rest_framework/templatetags/rest_framework.py | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/rest_framework/templates/rest_framework/base.html b/rest_framework/templates/rest_framework/base.html index 7f16482b78..e261d8c9d5 100644 --- a/rest_framework/templates/rest_framework/base.html +++ b/rest_framework/templates/rest_framework/base.html @@ -176,7 +176,7 @@

{{ name }}

HTTP {{ response.status_code }} {{ response.status_text }}{% for key, val in response_headers|items %}
-{{ key }}: {{ val|break_long_headers|urlize }}{% endfor %}
+{{ key }}: {{ val|urlize }}{% endfor %}
 
 {{ content|urlize }}
diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index e01568cf2c..3ff74e7cc2 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -313,14 +313,3 @@ def smart_urlquote_wrapper(matched_url): return smart_urlquote(matched_url) except ValueError: return None - - -@register.filter -def break_long_headers(header): - """ - Breaks headers longer than 160 characters (~page length) - when possible (are comma separated) - """ - if len(header) > 160 and ',' in header: - header = mark_safe('
' + ',
'.join(header.split(','))) - return header From 850fa8a6d2519b11f61d5a32a5ae769a717c971f Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Sun, 27 Apr 2025 14:19:53 +0100 Subject: [PATCH 2/3] Remove related test --- tests/test_templatetags.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 4b84f66474..7134c1bae0 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -8,8 +8,8 @@ from rest_framework.relations import Hyperlink from rest_framework.templatetags import rest_framework from rest_framework.templatetags.rest_framework import ( - add_nested_class, add_query_param, as_string, break_long_headers, - format_value, get_pagination_html, schema_links + add_nested_class, add_query_param, as_string, format_value, + get_pagination_html, schema_links ) from rest_framework.test import APIRequestFactory @@ -234,11 +234,6 @@ def to_html(self): get_pagination_html(pager) assert pager.called is True - def test_break_long_lines(self): - header = 'long test header,' * 20 - expected_header = '
' + ',
'.join(header.split(',')) - assert break_long_headers(header) == expected_header - class Issue1386Tests(TestCase): """ From beb2cf7e56fb7b0ce01e435d07c1f424557e6ddb Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Sun, 27 Apr 2025 14:21:11 +0100 Subject: [PATCH 3/3] Fix flake8 --- rest_framework/templatetags/rest_framework.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 1caec2cd5d..3ff74e7cc2 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -313,4 +313,3 @@ def smart_urlquote_wrapper(matched_url): return smart_urlquote(matched_url) except ValueError: return None -