diff options
author | Yehuda Katz <wycats@Yehuda-Katz.local> | 2010-01-31 19:17:42 -0800 |
---|---|---|
committer | Yehuda Katz <wycats@Yehuda-Katz.local> | 2010-01-31 19:39:13 -0800 |
commit | 4cbb9db0a5ff65b0a626a5b043331abefd89e717 (patch) | |
tree | a112ce55f5521ff31abf0e4357afcc170fc0a143 /actionpack/test | |
parent | 1c83fd2eff3fd174e1aba0512aa2dd8ecdadb2c7 (diff) | |
download | rails-4cbb9db0a5ff65b0a626a5b043331abefd89e717.tar.gz rails-4cbb9db0a5ff65b0a626a5b043331abefd89e717.tar.bz2 rails-4cbb9db0a5ff65b0a626a5b043331abefd89e717.zip |
For performance reasons, you can no longer call html_safe! on Strings. Instead, all Strings are always not html_safe?. Instead, you can get a SafeBuffer from a String by calling #html_safe, which will SafeBuffer.new(self).
* Additionally, instead of doing concat("</form>".html_safe), you can do
safe_concat("</form>"), which will skip both the flag set, and the flag
check.
* For the first pass, I converted virtually all #html_safe!s to #html_safe,
and the tests pass. A further optimization would be to try to use
#safe_concat as much as possible, reducing the performance impact if
we know up front that a String is safe.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/caching_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/controller/output_escaping_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/erb_util_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/template/safe_buffer_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/test_case_test.rb | 2 |
7 files changed, 10 insertions, 10 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index 8a13d1e5f1..de92fc56fd 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -611,7 +611,7 @@ class FragmentCachingTest < ActionController::TestCase @store.write('views/expensive', 'fragment content') fragment_computed = false - buffer = 'generated till now -> ' + buffer = 'generated till now -> '.html_safe @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } assert fragment_computed @@ -622,7 +622,7 @@ class FragmentCachingTest < ActionController::TestCase @store.write('views/expensive', 'fragment content') fragment_computed = false - buffer = 'generated till now -> ' + buffer = 'generated till now -> '.html_safe @controller.fragment_for(buffer, 'expensive') { fragment_computed = true } assert !fragment_computed diff --git a/actionpack/test/controller/output_escaping_test.rb b/actionpack/test/controller/output_escaping_test.rb index 7332f3f1e3..43a8c05cda 100644 --- a/actionpack/test/controller/output_escaping_test.rb +++ b/actionpack/test/controller/output_escaping_test.rb @@ -13,7 +13,7 @@ class OutputEscapingTest < ActiveSupport::TestCase test "escapeHTML shouldn't touch explicitly safe strings" do # TODO this seems easier to compose and reason about, but # this should be verified - assert_equal "<", ERB::Util.h("<".html_safe!) + assert_equal "<", ERB::Util.h("<".html_safe) end end diff --git a/actionpack/test/template/erb_util_test.rb b/actionpack/test/template/erb_util_test.rb index fa6b263965..06155b1f30 100644 --- a/actionpack/test/template/erb_util_test.rb +++ b/actionpack/test/template/erb_util_test.rb @@ -22,7 +22,7 @@ class ErbUtilTest < Test::Unit::TestCase end def test_html_escape_passes_html_escpe_unmodified - escaped = h("<p>".html_safe!) + escaped = h("<p>".html_safe) assert_equal "<p>", escaped assert escaped.html_safe? end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index caeca9db10..aafc318b76 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1170,7 +1170,7 @@ class FormHelperTest < ActionView::TestCase (field_helpers - %w(hidden_field)).each do |selector| src = <<-END_SRC def #{selector}(field, *args, &proc) - ("<label for='\#{field}'>\#{field.to_s.humanize}:</label> " + super + "<br/>").html_safe! + ("<label for='\#{field}'>\#{field.to_s.humanize}:</label> " + super + "<br/>").html_safe end END_SRC class_eval src, __FILE__, __LINE__ diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 553ec44fad..3635c7548e 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -335,19 +335,19 @@ class FormTagHelperTest < ActionView::TestCase expected = %(<fieldset><legend>Your details</legend>Hello world!</fieldset>) assert_dom_equal expected, output_buffer - self.output_buffer = '' + self.output_buffer = ''.html_safe field_set_tag { concat "Hello world!" } expected = %(<fieldset>Hello world!</fieldset>) assert_dom_equal expected, output_buffer - self.output_buffer = '' + self.output_buffer = ''.html_safe field_set_tag('') { concat "Hello world!" } expected = %(<fieldset>Hello world!</fieldset>) assert_dom_equal expected, output_buffer - self.output_buffer = '' + self.output_buffer = ''.html_safe field_set_tag('', :class => 'format') { concat "Hello world!" } expected = %(<fieldset class="format">Hello world!</fieldset>) diff --git a/actionpack/test/template/safe_buffer_test.rb b/actionpack/test/template/safe_buffer_test.rb index 6a18201d16..41a95e068b 100644 --- a/actionpack/test/template/safe_buffer_test.rb +++ b/actionpack/test/template/safe_buffer_test.rb @@ -16,7 +16,7 @@ class SafeBufferTest < ActionView::TestCase end test "Should NOT escape a safe value passed to it" do - @buffer << "<script>".html_safe! + @buffer << "<script>".html_safe assert_equal "<script>", @buffer end diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index 9a448ce328..be2c6b3108 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -160,7 +160,7 @@ module ActionView class AssertionsTest < ActionView::TestCase def render_from_helper form_tag('/foo') do - concat render(:text => '<ul><li>foo</li></ul>').html_safe! + safe_concat render(:text => '<ul><li>foo</li></ul>') end end helper_method :render_from_helper |