Skip to content
This repository
Browse code

Tag helper should output an attribute with the value 'false' instead …

…of omitting the attribute, if the associated option is false but not nil.
  • Loading branch information...
commit 4e9abdd7f1b4e05f8d1b50ddaa080b3ff63b92d9 1 parent 4c09210
Hongli Lai authored November 13, 2008 NZKoz committed November 13, 2008
10  actionpack/lib/action_view/helpers/tag_helper.rb
@@ -133,10 +133,12 @@ def tag_options(options, escape = true)
133 133
           unless options.blank?
134 134
             attrs = []
135 135
             if escape
136  
-              options.each do |key, value|
137  
-                next unless value
138  
-                value = BOOLEAN_ATTRIBUTES.include?(key) ? key : escape_once(value)
139  
-                attrs << %(#{key}="#{value}")
  136
+              options.each_pair do |key, value|
  137
+                if BOOLEAN_ATTRIBUTES.include?(key)
  138
+                  attrs << %(#{key}="#{key}") if value
  139
+                else
  140
+                  attrs << %(#{key}="#{escape_once(value)}") if !value.nil?
  141
+                end
140 142
               end
141 143
             else
142 144
               attrs = options.map { |key, value| %(#{key}="#{value}") }
2  actionpack/test/template/form_tag_helper_test.rb
@@ -235,7 +235,7 @@ def test_label_tag_id_sanitized
235 235
     assert_match VALID_HTML_ID, label_elem['for']
236 236
   end
237 237
 
238  
-  def test_boolean_optios
  238
+  def test_boolean_options
239 239
     assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
240 240
     assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
241 241
     assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
4  actionpack/test/template/tag_helper_test.rb
@@ -19,6 +19,10 @@ def test_tag_options_rejects_nil_option
19 19
     assert_equal "<p />", tag("p", :ignored => nil)
20 20
   end
21 21
 
  22
+  def test_tag_options_accepts_false_option
  23
+    assert_equal "<p value=\"false\" />", tag("p", :value => false)
  24
+  end
  25
+
22 26
   def test_tag_options_accepts_blank_option
23 27
     assert_equal "<p included=\"\" />", tag("p", :included => '')
24 28
   end

0 notes on commit 4e9abdd

Please sign in to comment.
Something went wrong with that request. Please try again.