aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2013-12-16 06:54:48 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2013-12-16 06:54:48 -0800
commite7b8769cbc821f07f1bd3505999da8d610bed538 (patch)
tree38c155f29c785a62940835445e0dce03a3224dac /activesupport/test
parent4b4aeabb3605bd0cbd7dde10c1d2ac990c65379a (diff)
parenta764938ad0ddb0aa73bb86215626f24b980e3f55 (diff)
downloadrails-e7b8769cbc821f07f1bd3505999da8d610bed538.tar.gz
rails-e7b8769cbc821f07f1bd3505999da8d610bed538.tar.bz2
rails-e7b8769cbc821f07f1bd3505999da8d610bed538.zip
Merge pull request #13321 from mezis/fix-safebuffer-interpolation-master
Fixes interpolation on SafeBuffer
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/safe_buffer_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index 047b89be2a..efa9d5e61f 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -140,4 +140,29 @@ class SafeBufferTest < ActiveSupport::TestCase
# should still be unsafe
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
+ end
+
+ 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 &lt;br/&gt; 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
+ end
+
+ test 'Should interpolate to a safe string' do
+ x = 'foo %{x} bar'.html_safe % { x: 'qux' }
+ assert x.html_safe?, 'should be safe'
+ end
end