diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 1e6277fb87f..1635ea00857 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -310,9 +310,9 @@ class AdminURLFieldWidget(forms.TextInput): html = super(AdminURLFieldWidget, self).render(name, value, attrs) if value: value = force_text(self._format_value(value)) - final_attrs = {'href': mark_safe(smart_urlquote(value))} + final_attrs = {'href': smart_urlquote(value)} html = format_html( - '

{0} {2}
{3} {4}

', + '

{0} {2}
{3} {4}

', _('Currently:'), flatatt(final_attrs), value, _('Change:'), html ) diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py index fa599c618c3..b3fff1fecca 100644 --- a/tests/regressiontests/admin_widgets/tests.py +++ b/tests/regressiontests/admin_widgets/tests.py @@ -299,18 +299,24 @@ class AdminURLWidgetTest(DjangoTestCase): w = widgets.AdminURLFieldWidget() self.assertHTMLEqual( conditional_escape(w.render('test', 'http://example-äüö.com')), - '

Currently:http://example-äüö.com
Change:

' + '

Currently: http://example-äüö.com
Change:

' ) def test_render_quoting(self): + # WARNING: Don't use assertHTMLEqual in that testcase! + # assertHTMLEqual will get rid of some escapes which are tested here! w = widgets.AdminURLFieldWidget() - self.assertHTMLEqual( - conditional_escape(w.render('test', 'http://example.com/some text')), - '

Currently:http://example.com/<sometag>some text</sometag>
Change:

' + self.assertEqual( + w.render('test', 'http://example.com/some text'), + '

Currently: http://example.com/<sometag>some text</sometag>
Change:

' ) - self.assertHTMLEqual( - conditional_escape(w.render('test', 'http://example-äüö.com/some text')), - '

Currently:http://example-äüö.com/<sometag>some text</sometag>
Change:

' + self.assertEqual( + w.render('test', 'http://example-äüö.com/some text'), + '

Currently: http://example-äüö.com/<sometag>some text</sometag>
Change:

' + ) + self.assertEqual( + w.render('test', 'http://www.example.com/%C3%A4">"'), + '

Currently: http://www.example.com/%C3%A4"><script>alert("XSS!")</script>"
Change:

' )