Commits

Mike Orr  committed 4aa27b5

Fix bug with 'id_' argument to tag helpers.

  • Participants
  • Parent commits b82df08

Comments (0)

Files changed (2)

File tests/test_tags.py

 from webhelpers.html import HTML
 from webhelpers.html.tags import *
 
+from util import raises
+
 class TestFormTagHelper(object):
     def test_check_box(self):
         eq_(
             u'<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />'
         )
 
+    def test_multiple_id_bug(self):
+        # Don't set multiple id attributes for 'id_' argument.
+        eq_(
+            text("spam", "pizza", id="eggs"),
+            u'<input id="eggs" name="spam" type="text" value="pizza" />')
+        eq_(
+            text("spam", "pizza", id_="eggs"), 
+            u'<input id="eggs" name="spam" type="text" value="pizza" />')
+        eq_(
+            select("spam", [1,2], [2], id="eggs"),
+            u'<select id="eggs" name="spam">\n<option selected="selected" value="2">2</option>\n</select>')
+        eq_(
+            select("spam", [1,2], [2], id_="eggs"),
+            u'<select id="eggs" name="spam">\n<option selected="selected" value="2">2</option>\n</select>')
+
+    def test_id_and_id_(self):
+        raises(TypeError, text, "spam", "pizza", id="fubar", id_="eggs")
+        
+
     
 class TestLinkHelper(object):
     def test_link_tag_with_query(self):

File webhelpers/html/tags.py

     attrs["value"] = value
 
 def _set_id_attr(attrs, id, name):
-    if id is None:
+    if "id_" in attrs and id is not None:
+        raise TypeError("can't pass both 'id' and 'id_' arguments")
+    elif "id_" in attrs:
+        attrs["id"] = attrs.pop("id_")
+    elif id is None:
         attrs["id"] = _make_safe_id_component(name)
     elif id != "":
         attrs["id"] = id