Ticket #15182: clearablefieldwidget-encode-to-html.patch
File clearablefieldwidget-encode-to-html.patch, 2.3 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/forms/tests/widgets.py
1086 1086 self.assertEqual(widget.render('myfile', FakeFieldFile()), 1087 1087 u'Currently: <a target="_blank" href="something">something</a> <input type="checkbox" name="myfile-clear" id="myfile-clear_id" /> <label for="myfile-clear_id">Clear</label><br />Change: <input type="file" name="myfile" />') 1088 1088 1089 def test_encode_field_to_html(self): 1090 """ 1091 A ClearableFileInput should encode values when render HTML. 1092 """ 1093 1094 class StrangeFieldFile(object): 1095 url = "something?chapter=1§=2©=3&lang=en" 1096 1097 def __unicode__(self): 1098 return u'''something<div onclick="alert('oops')">.jpg''' 1099 1100 widget = ClearableFileInput() 1101 widget.is_required = False 1102 field = StrangeFieldFile() 1103 output = widget.render('myfile', field) 1104 self.assertFalse(field.url in output) 1105 self.assertTrue(u'href="something?chapter=1&sect=2&copy=3&lang=en"' in output) 1106 self.assertFalse(unicode(field) in output) 1107 self.assertTrue(u'something<div onclick="alert('oops')">.jpg' in output) 1108 1089 1109 def test_clear_input_renders_only_if_not_required(self): 1090 1110 """ 1091 1111 A ClearableFileInput with is_required=False does not render a clear -
django/forms/widgets.py
330 330 if value and hasattr(value, "url"): 331 331 template = self.template_with_initial 332 332 substitutions['initial'] = (u'<a target="_blank" href="%s">%s</a>' 333 % (value.url, value)) 333 % (escape(value.url), 334 escape(force_unicode(value)))) 334 335 if not self.is_required: 335 336 checkbox_name = self.clear_checkbox_name(name) 336 337 checkbox_id = self.clear_checkbox_id(checkbox_name)