mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-05-21 21:16:20 +03:00
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 <auvipy@gmail.com> Co-authored-by: Bruno Alla <alla.brunoo@gmail.com>
This commit is contained in:
parent
376026ce35
commit
78e97074e7
|
@ -176,7 +176,7 @@
|
|||
|
||||
<div class="response-info" aria-label="{% trans "response info" %}">
|
||||
<pre class="prettyprint"><span class="meta nocode"><b>HTTP {{ response.status_code }} {{ response.status_text }}</b>{% for key, val in response_headers|items %}
|
||||
<b>{{ key }}:</b> <span class="lit">{{ val|break_long_headers|urlize }}</span>{% endfor %}
|
||||
<b>{{ key }}:</b> <span class="lit">{{ val|urlize }}</span>{% endfor %}
|
||||
|
||||
</span>{{ content|urlize }}</pre>
|
||||
</div>
|
||||
|
|
|
@ -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('<br> ' + ', <br>'.join(escape(header).split(',')))
|
||||
return header
|
||||
|
|
|
@ -8,8 +8,8 @@ from rest_framework.compat import coreapi, coreschema
|
|||
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 @@ class TemplateTagTests(TestCase):
|
|||
get_pagination_html(pager)
|
||||
assert pager.called is True
|
||||
|
||||
def test_break_long_lines(self):
|
||||
header = 'long test header,' * 20
|
||||
expected_header = '<br> ' + ', <br>'.join(header.split(','))
|
||||
assert break_long_headers(header) == expected_header
|
||||
|
||||
|
||||
class Issue1386Tests(TestCase):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user