summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2011-01-02 17:34:52 +0000
committerRamiro Morales <cramm0@gmail.com>2011-01-02 17:34:52 +0000
commit0f783b7f4eac037e22875eeeb6dc85c26b2a65f4 (patch)
tree7600364217fb5f354bfa1283a98e9562cbfbec6a /tests
parent544ab30ed71e0d78c4c061008758de29ff79e8f7 (diff)
Fixed #2986 -- Made the JavaScript code that drives related model instance addition in a popup window handle a model representation containing new lines. Also, moved the escapejs functionality yoo django.utils.html so it can be used from Python code. Thanks andrewwatts for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/admin_views/tests.py16
-rw-r--r--tests/regressiontests/utils/html.py12
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index eb35b41860..90abfa8dbb 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -107,6 +107,22 @@ class AdminViewBasicTest(TestCase):
response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data)
self.assertEqual(response.status_code, 302) # redirect somewhere
+ def testPopupAddPost(self):
+ """
+ Ensure http response from a popup is properly escaped.
+ """
+ post_data = {
+ '_popup': u'1',
+ 'title': u'title with a new\nline',
+ 'content': u'some content',
+ 'date_0': u'2010-09-10',
+ 'date_1': u'14:55:39',
+ }
+ response = self.client.post('/test_admin/%s/admin_views/article/add/' % self.urlbit, post_data)
+ self.failUnlessEqual(response.status_code, 200)
+ self.assertContains(response, 'dismissAddAnotherPopup')
+ self.assertContains(response, 'title with a new\u000Aline')
+
# Post data for edit inline
inline_post_data = {
"name": u"Test section",
diff --git a/tests/regressiontests/utils/html.py b/tests/regressiontests/utils/html.py
index a9b0d337f2..3acb218cd1 100644
--- a/tests/regressiontests/utils/html.py
+++ b/tests/regressiontests/utils/html.py
@@ -109,3 +109,15 @@ class TestUtilsHtml(unittest.TestCase):
)
for value, output in items:
self.check_output(f, value, output)
+
+ def test_escapejs(self):
+ f = html.escapejs
+ items = (
+ (u'"double quotes" and \'single quotes\'', u'\\u0022double quotes\\u0022 and \\u0027single quotes\\u0027'),
+ (ur'\ : backslashes, too', u'\\u005C : backslashes, too'),
+ (u'and lots of whitespace: \r\n\t\v\f\b', u'and lots of whitespace: \\u000D\\u000A\\u0009\\u000B\\u000C\\u0008'),
+ (ur'<script>and this</script>', u'\\u003Cscript\\u003Eand this\\u003C/script\\u003E'),
+ (u'paragraph separator:\u2029and line separator:\u2028', u'paragraph separator:\\u2029and line separator:\\u2028'),
+ )
+ for value, output in items:
+ self.check_output(f, value, output)