Skip to content
This repository
Browse code

Merge pull request #5619 from jcoleman/textarea-newline-fix-breaks-haml

Textarea newline fix breaks haml (3-2-stable)
  • Loading branch information...
commit 4f66586bbfacbce4c07f2b9d8d142be1bf6d4e5e 1 parent 5f37260
Santiago Pastorino authored March 27, 2012
2  actionpack/lib/action_view/helpers/form_helper.rb
@@ -1072,7 +1072,7 @@ def to_text_area_tag(options = {})
1072 1072
           options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
1073 1073
         end
1074 1074
 
1075  
-        content_tag("textarea", "\n#{options.delete('value') || value_before_type_cast(object)}", options)
  1075
+        content_tag("textarea", options.delete('value') || value_before_type_cast(object), options)
1076 1076
       end
1077 1077
 
1078 1078
       def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
6  actionpack/lib/action_view/helpers/tag_helper.rb
@@ -17,6 +17,10 @@ module TagHelper
17 17
                            autofocus novalidate formnovalidate open pubdate).to_set
18 18
       BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map {|attribute| attribute.to_sym })
19 19
 
  20
+      PRE_CONTENT_STRINGS = {
  21
+        :textarea => "\n"
  22
+      }
  23
+
20 24
       # Returns an empty HTML tag of type +name+ which by default is XHTML
21 25
       # compliant. Set +open+ to true to create an open tag compatible
22 26
       # with HTML 4.0 and below. Add HTML attributes by passing an attributes
@@ -125,7 +129,7 @@ def escape_once(html)
125 129
 
126 130
         def content_tag_string(name, content, options, escape = true)
127 131
           tag_options = tag_options(options, escape) if options
128  
-          "<#{name}#{tag_options}>#{escape ? ERB::Util.h(content) : content}</#{name}>".html_safe
  132
+          "<#{name}#{tag_options}>#{PRE_CONTENT_STRINGS[name.to_sym]}#{escape ? ERB::Util.h(content) : content}</#{name}>".html_safe
129 133
         end
130 134
 
131 135
         def tag_options(options, escape = true)
12  actionpack/test/template/form_tag_helper_test.rb
@@ -216,19 +216,19 @@ def test_select_tag_with_prompt_and_include_blank
216 216
 
217 217
   def test_text_area_tag_size_string
218 218
     actual = text_area_tag "body", "hello world", "size" => "20x40"
219  
-    expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
  219
+    expected = %(<textarea cols="20" id="body" name="body" rows="40">\nhello world</textarea>)
220 220
     assert_dom_equal expected, actual
221 221
   end
222 222
 
223 223
   def test_text_area_tag_size_symbol
224 224
     actual = text_area_tag "body", "hello world", :size => "20x40"
225  
-    expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
  225
+    expected = %(<textarea cols="20" id="body" name="body" rows="40">\nhello world</textarea>)
226 226
     assert_dom_equal expected, actual
227 227
   end
228 228
 
229 229
   def test_text_area_tag_should_disregard_size_if_its_given_as_an_integer
230 230
     actual = text_area_tag "body", "hello world", :size => 20
231  
-    expected = %(<textarea id="body" name="body">hello world</textarea>)
  231
+    expected = %(<textarea id="body" name="body">\nhello world</textarea>)
232 232
     assert_dom_equal expected, actual
233 233
   end
234 234
 
@@ -239,19 +239,19 @@ def test_text_area_tag_id_sanitized
239 239
 
240 240
   def test_text_area_tag_escape_content
241 241
     actual = text_area_tag "body", "<b>hello world</b>", :size => "20x40"
242  
-    expected = %(<textarea cols="20" id="body" name="body" rows="40">&lt;b&gt;hello world&lt;/b&gt;</textarea>)
  242
+    expected = %(<textarea cols="20" id="body" name="body" rows="40">\n&lt;b&gt;hello world&lt;/b&gt;</textarea>)
243 243
     assert_dom_equal expected, actual
244 244
   end
245 245
 
246 246
   def test_text_area_tag_unescaped_content
247 247
     actual = text_area_tag "body", "<b>hello world</b>", :size => "20x40", :escape => false
248  
-    expected = %(<textarea cols="20" id="body" name="body" rows="40"><b>hello world</b></textarea>)
  248
+    expected = %(<textarea cols="20" id="body" name="body" rows="40">\n<b>hello world</b></textarea>)
249 249
     assert_dom_equal expected, actual
250 250
   end
251 251
 
252 252
   def test_text_area_tag_unescaped_nil_content
253 253
     actual = text_area_tag "body", nil, :escape => false
254  
-    expected = %(<textarea id="body" name="body"></textarea>)
  254
+    expected = %(<textarea id="body" name="body">\n</textarea>)
255 255
     assert_dom_equal expected, actual
256 256
   end
257 257
 

0 notes on commit 4f66586

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