diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 061988c6c03..c761ea857da 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -403,7 +403,7 @@ class Textarea(Widget): def render(self, name, value, attrs=None): if value is None: value = '' final_attrs = self.build_attrs(attrs, name=name) - return format_html('', + return format_html('', flatatt(final_attrs), force_text(value)) diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py index 6e9c269356e..bec31d12d7a 100644 --- a/tests/regressiontests/forms/models.py +++ b/tests/regressiontests/forms/models.py @@ -83,4 +83,8 @@ class Group(models.Model): class Cheese(models.Model): - name = models.CharField(max_length=100) + name = models.CharField(max_length=100) + + +class Article(models.Model): + content = models.TextField() diff --git a/tests/regressiontests/forms/templates/forms/article_form.html b/tests/regressiontests/forms/templates/forms/article_form.html new file mode 100644 index 00000000000..cde85051f64 --- /dev/null +++ b/tests/regressiontests/forms/templates/forms/article_form.html @@ -0,0 +1,8 @@ + +
+ + + diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index 8e2150cea3b..6708e54c793 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -18,4 +18,4 @@ from .regressions import FormsRegressionsTestCase from .util import FormsUtilTestCase from .validators import TestFieldWithValidators from .widgets import (FormsWidgetTestCase, FormsI18NWidgetsTestCase, - WidgetTests, ClearableFileInputTests) + WidgetTests, LiveWidgetTests, ClearableFileInputTests) diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py index 88469a79e88..31c0e65c7c1 100644 --- a/tests/regressiontests/forms/tests/widgets.py +++ b/tests/regressiontests/forms/tests/widgets.py @@ -4,7 +4,9 @@ from __future__ import unicode_literals import copy import datetime +from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase from django.core.files.uploadedfile import SimpleUploadedFile +from django.core.urlresolvers import reverse from django.forms import * from django.forms.widgets import RadioFieldRenderer from django.utils import formats @@ -15,6 +17,8 @@ from django.test import TestCase from django.test.utils import override_settings from django.utils.encoding import python_2_unicode_compatible +from ..models import Article + class FormsWidgetTestCase(TestCase): # Each Widget class corresponds to an HTML form widget. A Widget knows how to @@ -1095,6 +1099,22 @@ class WidgetTests(TestCase): self.assertFalse(form.is_valid()) +class LiveWidgetTests(AdminSeleniumWebDriverTestCase): + urls = 'regressiontests.forms.urls' + + def test_textarea_trailing_newlines(self): + """ + Test that a roundtrip on a ModelForm doesn't alter the TextField value + """ + article = Article.objects.create(content="\nTst\n") + self.selenium.get('%s%s' % (self.live_server_url, + reverse('article_form', args=[article.pk]))) + self.selenium.find_element_by_id('submit').submit() + article = Article.objects.get(pk=article.pk) + # Should be "\nTst\n" after #19251 is fixed + self.assertEqual(article.content, "\r\nTst\r\n") + + @python_2_unicode_compatible class FakeFieldFile(object): """ diff --git a/tests/regressiontests/forms/urls.py b/tests/regressiontests/forms/urls.py new file mode 100644 index 00000000000..b482b6c45c0 --- /dev/null +++ b/tests/regressiontests/forms/urls.py @@ -0,0 +1,9 @@ +from django.conf.urls import patterns, url +from django.views.generic.edit import UpdateView + +from .views import ArticleFormView + + +urlpatterns = patterns('', + url(r'^/model_form/(?P