Refs #15667 -- Prevented newlines in attrs.html widget rendering.
Removed the trailing newline from widget attrs.html template. The solution may be revisited by fixing refs #9198 but not for Django 1.11. Thanks Dmitry Ivanchenko for the report and Preston Timmons for advice.
This commit is contained in:
parent
7a6863c338
commit
12cefee5d8
|
@ -1 +1 @@
|
|||
{% for name, value in widget.attrs.items %} {{ name }}{% if not value is True %}="{{ value }}"{% endif %}{% endfor %}
|
||||
{% for name, value in widget.attrs.items %} {{ name }}{% if not value is True %}="{{ value }}"{% endif %}{% endfor %}
|
|
@ -17,11 +17,12 @@ class WidgetTest(SimpleTestCase):
|
|||
cls.renderers = [cls.django_renderer] + ([cls.jinja2_renderer] if cls.jinja2_renderer else [])
|
||||
super(WidgetTest, cls).setUpClass()
|
||||
|
||||
def check_html(self, widget, name, value, html='', attrs=None, **kwargs):
|
||||
def check_html(self, widget, name, value, html='', attrs=None, strict=False, **kwargs):
|
||||
assertEqual = self.assertEqual if strict else self.assertHTMLEqual
|
||||
if self.jinja2_renderer:
|
||||
output = widget.render(name, value, attrs=attrs, renderer=self.jinja2_renderer, **kwargs)
|
||||
# Django escapes quotes with '"' while Jinja2 uses '"'.
|
||||
self.assertHTMLEqual(output.replace('"', '"'), html)
|
||||
assertEqual(output.replace('"', '"'), html)
|
||||
|
||||
output = widget.render(name, value, attrs=attrs, renderer=self.django_renderer, **kwargs)
|
||||
self.assertHTMLEqual(output, html)
|
||||
assertEqual(output, html)
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.forms import Widget
|
||||
from django.test import SimpleTestCase
|
||||
from django.forms.widgets import Input
|
||||
|
||||
from .base import WidgetTest
|
||||
|
||||
|
||||
class WidgetTests(SimpleTestCase):
|
||||
class WidgetTests(WidgetTest):
|
||||
|
||||
def test_value_omitted_from_data(self):
|
||||
widget = Widget()
|
||||
self.assertIs(widget.value_omitted_from_data({}, {}, 'field'), True)
|
||||
self.assertIs(widget.value_omitted_from_data({'field': 'value'}, {}, 'field'), False)
|
||||
|
||||
def test_no_trailing_newline_in_attrs(self):
|
||||
self.check_html(Input(), 'name', 'value', strict=True, html='<input type="None" name="name" value="value" />')
|
||||
|
|
Loading…
Reference in New Issue