Skip to content

Commit 78e9707

Browse files
tomchristieauvipybrowniebroke
authored
Drop HTML line breaks on long headers in browsable API (#9438)
* Drop HTML line breaks on long headers * Remove related test * Fix flake8 --------- Co-authored-by: Asif Saif Uddin <[email protected]> Co-authored-by: Bruno Alla <[email protected]>
1 parent 376026c commit 78e9707

File tree

3 files changed

+3
-19
lines changed

3 files changed

+3
-19
lines changed

rest_framework/templates/rest_framework/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ <h1>{{ name }}</h1>
176176

177177
<div class="response-info" aria-label="{% trans "response info" %}">
178178
<pre class="prettyprint"><span class="meta nocode"><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% for key, val in response_headers|items %}
179-
<b>{{ key }}:</b> <span class="lit">{{ val|break_long_headers|urlize }}</span>{% endfor %}
179+
<b>{{ key }}:</b> <span class="lit">{{ val|urlize }}</span>{% endfor %}
180180

181181
</span>{{ content|urlize }}</pre>
182182
</div>

rest_framework/templatetags/rest_framework.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,3 @@ def smart_urlquote_wrapper(matched_url):
313313
return smart_urlquote(matched_url)
314314
except ValueError:
315315
return None
316-
317-
318-
@register.filter
319-
def break_long_headers(header):
320-
"""
321-
Breaks headers longer than 160 characters (~page length)
322-
when possible (are comma separated)
323-
"""
324-
if len(header) > 160 and ',' in header:
325-
header = mark_safe('<br> ' + ', <br>'.join(escape(header).split(',')))
326-
return header

tests/test_templatetags.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from rest_framework.relations import Hyperlink
99
from rest_framework.templatetags import rest_framework
1010
from rest_framework.templatetags.rest_framework import (
11-
add_nested_class, add_query_param, as_string, break_long_headers,
12-
format_value, get_pagination_html, schema_links
11+
add_nested_class, add_query_param, as_string, format_value,
12+
get_pagination_html, schema_links
1313
)
1414
from rest_framework.test import APIRequestFactory
1515

@@ -234,11 +234,6 @@ def to_html(self):
234234
get_pagination_html(pager)
235235
assert pager.called is True
236236

237-
def test_break_long_lines(self):
238-
header = 'long test header,' * 20
239-
expected_header = '<br> ' + ', <br>'.join(header.split(','))
240-
assert break_long_headers(header) == expected_header
241-
242237

243238
class Issue1386Tests(TestCase):
244239
"""

0 commit comments

Comments
 (0)