diff options
Diffstat (limited to 'activesupport/test/safe_buffer_test.rb')
-rw-r--r-- | activesupport/test/safe_buffer_test.rb | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 18fb6d2fbf..4d083ab773 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'active_support/core_ext/string/inflections' -require 'yaml' +require "abstract_unit" +require "active_support/core_ext/string/inflections" +require "yaml" class SafeBufferTest < ActiveSupport::TestCase def setup @@ -8,7 +8,7 @@ class SafeBufferTest < ActiveSupport::TestCase end def test_titleize - assert_equal 'Foo', "foo".html_safe.titleize + assert_equal "Foo", "foo".html_safe.titleize end test "Should look like a string" do @@ -46,26 +46,26 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should be converted to_yaml" do - str = 'hello!' + str = "hello!" buf = ActiveSupport::SafeBuffer.new str yaml = buf.to_yaml assert_match(/^--- #{str}/, yaml) - assert_equal 'hello!', YAML.load(yaml) + assert_equal "hello!", YAML.load(yaml) end test "Should work in nested to_yaml conversion" do - str = 'hello!' - data = { 'str' => ActiveSupport::SafeBuffer.new(str) } + str = "hello!" + data = { "str" => ActiveSupport::SafeBuffer.new(str) } yaml = YAML.dump data - assert_equal({'str' => str}, YAML.load(yaml)) + assert_equal({ "str" => str }, YAML.load(yaml)) end test "Should work with primitive-like-strings in to_yaml conversion" do - assert_equal 'true', YAML.load(ActiveSupport::SafeBuffer.new('true').to_yaml) - assert_equal 'false', YAML.load(ActiveSupport::SafeBuffer.new('false').to_yaml) - assert_equal '1', YAML.load(ActiveSupport::SafeBuffer.new('1').to_yaml) - assert_equal '1.1', YAML.load(ActiveSupport::SafeBuffer.new('1.1').to_yaml) + assert_equal "true", YAML.load(ActiveSupport::SafeBuffer.new("true").to_yaml) + assert_equal "false", YAML.load(ActiveSupport::SafeBuffer.new("false").to_yaml) + assert_equal "1", YAML.load(ActiveSupport::SafeBuffer.new("1").to_yaml) + assert_equal "1.1", YAML.load(ActiveSupport::SafeBuffer.new("1.1").to_yaml) end test "Should work with underscore" do @@ -74,31 +74,31 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should not return safe buffer from gsub" do - altered_buffer = @buffer.gsub('', 'asdf') - assert_equal 'asdf', altered_buffer + altered_buffer = @buffer.gsub("", "asdf") + assert_equal "asdf", altered_buffer assert !altered_buffer.html_safe? end test "Should not return safe buffer from gsub!" do - @buffer.gsub!('', 'asdf') - assert_equal 'asdf', @buffer + @buffer.gsub!("", "asdf") + assert_equal "asdf", @buffer assert !@buffer.html_safe? end test "Should escape dirty buffers on add" do clean = "hello".html_safe - @buffer.gsub!('', '<>') + @buffer.gsub!("", "<>") assert_equal "hello<>", clean + @buffer end test "Should concat as a normal string when safe" do clean = "hello".html_safe - @buffer.gsub!('', '<>') + @buffer.gsub!("", "<>") assert_equal "<>hello", @buffer + clean end test "Should preserve html_safe? status on copy" do - @buffer.gsub!('', '<>') + @buffer.gsub!("", "<>") assert !@buffer.dup.html_safe? end @@ -110,7 +110,7 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should raise an error when safe_concat is called on unsafe buffers" do - @buffer.gsub!('', '<>') + @buffer.gsub!("", "<>") assert_raise ActiveSupport::SafeBuffer::SafeConcatError do @buffer.safe_concat "BUSTED" end @@ -121,12 +121,12 @@ class SafeBufferTest < ActiveSupport::TestCase end test "clone_empty returns an empty buffer" do - assert_equal '', ActiveSupport::SafeBuffer.new('foo').clone_empty + assert_equal "", ActiveSupport::SafeBuffer.new("foo").clone_empty end test "clone_empty keeps the original dirtyness" do assert @buffer.clone_empty.html_safe? - assert !@buffer.gsub!('', '').clone_empty.html_safe? + assert !@buffer.gsub!("", "").clone_empty.html_safe? end test "Should be safe when sliced if original value was safe" do @@ -136,7 +136,7 @@ class SafeBufferTest < ActiveSupport::TestCase end test "Should continue unsafe on slice" do - x = 'foo'.html_safe.gsub!('f', '<script>alert("lolpwnd");</script>') + x = "foo".html_safe.gsub!("f", '<script>alert("lolpwnd");</script>') # calling gsub! makes the dirty flag true assert !x.html_safe?, "should not be safe" @@ -148,33 +148,33 @@ class SafeBufferTest < ActiveSupport::TestCase assert !y.html_safe?, "should not be safe" end - test 'Should work with interpolation (array argument)' do - x = 'foo %s bar'.html_safe % ['qux'] - assert_equal 'foo qux bar', x + test "Should work with interpolation (array argument)" do + x = "foo %s bar".html_safe % ["qux"] + assert_equal "foo qux bar", x end - test 'Should work with interpolation (hash argument)' do - x = 'foo %{x} bar'.html_safe % { x: 'qux' } - assert_equal 'foo qux bar', x + test "Should work with interpolation (hash argument)" do + x = "foo %{x} bar".html_safe % { x: "qux" } + assert_equal "foo qux bar", x end - test 'Should escape unsafe interpolated args' do - x = 'foo %{x} bar'.html_safe % { x: '<br/>' } - assert_equal 'foo <br/> bar', x + test "Should escape unsafe interpolated args" do + x = "foo %{x} bar".html_safe % { x: "<br/>" } + assert_equal "foo <br/> bar", x end - test 'Should not escape safe interpolated args' do - x = 'foo %{x} bar'.html_safe % { x: '<br/>'.html_safe } - assert_equal 'foo <br/> bar', x + test "Should not escape safe interpolated args" do + x = "foo %{x} bar".html_safe % { x: "<br/>".html_safe } + assert_equal "foo <br/> bar", x end - test 'Should interpolate to a safe string' do - x = 'foo %{x} bar'.html_safe % { x: 'qux' } - assert x.html_safe?, 'should be safe' + test "Should interpolate to a safe string" do + x = "foo %{x} bar".html_safe % { x: "qux" } + assert x.html_safe?, "should be safe" end - test 'Should not affect frozen objects when accessing characters' do - x = 'Hello'.html_safe + test "Should not affect frozen objects when accessing characters" do + x = "Hello".html_safe assert_equal x[/a/, 1], nil end end |