diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-07-07 08:20:25 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-07-07 08:20:25 -0700 |
commit | 3e953d48a2db35969de8fb7ca3324b65b2e4b5fb (patch) | |
tree | 48aaf5a21567b6c8a08540e97608a945d72ce138 | |
parent | 7d384ddb2de46f584cb885c8b3944532ac3ac07c (diff) | |
parent | 06388b07791a24e9d3351a74bfdf23809bb1e69b (diff) | |
download | rails-3e953d48a2db35969de8fb7ca3324b65b2e4b5fb.tar.gz rails-3e953d48a2db35969de8fb7ca3324b65b2e4b5fb.tar.bz2 rails-3e953d48a2db35969de8fb7ca3324b65b2e4b5fb.zip |
Merge pull request #11317 from ma2gedev/enforcer_tag_option
Added an `enforce_utf8` hash option for `form_tag` method
-rw-r--r-- | actionview/CHANGELOG.md | 20 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/form_tag_helper.rb | 4 | ||||
-rw-r--r-- | actionview/test/template/form_tag_helper_test.rb | 17 |
3 files changed, 39 insertions, 2 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 921ea2be6f..64393b4089 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,23 @@ +* Added an `enforce_utf8` hash option for `form_tag` method. + + Control to output a hidden input tag with name `utf8` without monkey + patching. + + Before: + + form_tag + # => '<form>..<input name="utf8" type="hidden" value="✓" />..</form>' + + After: + + form_tag + # => '<form>..<input name="utf8" type="hidden" value="✓" />..</form>' + + form_tag({}, { :enforce_utf8 => false }) + # => '<form>....</form>' + + *ma2gedev* + * Remove the deprecated `include_seconds` argument from `distance_of_time_in_words`, pass in an `:include_seconds` hash option to use this feature. diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 3fa7696b83..142c27ace0 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -38,6 +38,7 @@ module ActionView # * A list of parameters to feed to the URL the form will be posted to. # * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the # submit behavior. By default this behavior is an ajax submit. + # * <tt>:enforce_utf8</tt> - If set to false, a hidden input with name utf8 is not output. # # ==== Examples # form_tag('/posts') @@ -719,7 +720,8 @@ module ActionView method_tag(method) + token_tag(authenticity_token) end - tags = utf8_enforcer_tag << method_tag + enforce_utf8 = html_options.delete("enforce_utf8") { true } + tags = (enforce_utf8 ? utf8_enforcer_tag : ''.html_safe) << method_tag content_tag(:div, tags, :style => 'margin:0;padding:0;display:inline') end diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 70fc6a588b..22bf438a56 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -12,9 +12,10 @@ class FormTagHelperTest < ActionView::TestCase def hidden_fields(options = {}) method = options[:method] + enforce_utf8 = options.fetch(:enforce_utf8, true) txt = %{<div style="margin:0;padding:0;display:inline">} - txt << %{<input name="utf8" type="hidden" value="✓" />} + txt << %{<input name="utf8" type="hidden" value="✓" />} if enforce_utf8 if method && !%w(get post).include?(method.to_s) txt << %{<input name="_method" type="hidden" value="#{method}" />} end @@ -110,6 +111,20 @@ class FormTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_form_tag_enforce_utf8_true + actual = form_tag({}, { :enforce_utf8 => true }) + expected = whole_form("http://www.example.com", :enforce_utf8 => true) + assert_dom_equal expected, actual + assert actual.html_safe? + end + + def test_form_tag_enforce_utf8_false + actual = form_tag({}, { :enforce_utf8 => false }) + expected = whole_form("http://www.example.com", :enforce_utf8 => false) + assert_dom_equal expected, actual + assert actual.html_safe? + end + def test_form_tag_with_block_in_erb output_buffer = render_erb("<%= form_tag('http://www.example.com') do %>Hello world!<% end %>") |