Mercurial > genshi > genshi-test
changeset 909:585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
author | cmlenz |
---|---|
date | Mon, 10 May 2010 15:03:22 +0000 |
parents | 5fd4a1e28351 |
children | d25c353a341d 8cef75b02ac1 |
files | ChangeLog genshi/filters/html.py genshi/filters/tests/html.py |
diffstat | 3 files changed, 21 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ * Fix for error in how `HTMLFormFiller` would handle `textarea` elements if no value was not supplied form them. + * The `HTMLFormFiller` now correctly handles check boxes and radio buttons + with an empty `value` attribute. Version 0.6
--- a/genshi/filters/html.py +++ b/genshi/filters/html.py @@ -100,13 +100,13 @@ declval = attrs.get('value') checked = False if isinstance(value, (list, tuple)): - if declval: + if declval is not None: checked = declval in [unicode(v) for v in value] else: checked = any(value) else: - if declval: + if declval is not None: checked = declval == unicode(value) elif type == 'checkbox': checked = bool(value)
--- a/genshi/filters/tests/html.py +++ b/genshi/filters/tests/html.py @@ -114,7 +114,7 @@ <textarea name="bar">Original value</textarea> </p></form>""", html.render()) - def test_fill_input_checkbox_no_value(self): + def test_fill_input_checkbox_single_value_auto_no_value(self): html = HTML("""<form><p> <input type="checkbox" name="foo" /> </p></form>""") | HTMLFormFiller() @@ -196,6 +196,22 @@ <input type="radio" name="foo" value="1"/> </p></form>""", (html | HTMLFormFiller(data={'foo': ['2']})).render()) + def test_fill_input_radio_empty_string(self): + html = HTML("""<form><p> + <input type="radio" name="foo" value="" /> + </p></form>""") + self.assertEquals("""<form><p> + <input type="radio" name="foo" value="" checked="checked"/> + </p></form>""", (html | HTMLFormFiller(data={'foo': ''})).render()) + + def test_fill_input_radio_multi_empty_string(self): + html = HTML("""<form><p> + <input type="radio" name="foo" value="" /> + </p></form>""") + self.assertEquals("""<form><p> + <input type="radio" name="foo" value="" checked="checked"/> + </p></form>""", (html | HTMLFormFiller(data={'foo': ['']})).render()) + def test_fill_select_no_value_auto(self): html = HTML("""<form><p> <select name="foo">