diff options
author | Matthew Landauer <matthew@openaustralia.org> | 2013-01-25 15:12:16 +1100 |
---|---|---|
committer | Matthew Landauer <matthew@openaustralia.org> | 2013-01-25 15:12:16 +1100 |
commit | 4e74f0fcdcb0820865689cc0595cf0c83aee7cab (patch) | |
tree | 1fd4a83516acaad73d88f0d7f011caf045ab5a17 /spec/lib | |
parent | 65680320bee44812394041492c8492e95b1a3d78 (diff) | |
parent | a67666e34c280d2b9eb613f57d96ba4ee5fcd749 (diff) |
Merge branch 'rails_xss' into rails-3-spike
Conflicts:
Gemfile
Gemfile.lock
config/environment.rb
lib/i18n_fixes.rb
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/i18n_interpolation.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/lib/i18n_interpolation.rb b/spec/lib/i18n_interpolation.rb index 6b745059c..e8d046757 100644 --- a/spec/lib/i18n_interpolation.rb +++ b/spec/lib/i18n_interpolation.rb @@ -8,5 +8,43 @@ describe "when using i18n" do result = _('Hello {{dip}}', :dip => 'hummus') result.should == 'Hello hummus' end + + it "should assume that simple translations are always html safe" do + _("Hello").should be_html_safe + end + end +describe "gettext_interpolate" do + context "html unsafe string" do + let(:string) { "Hello {{a}}" } + + it "should give an unsafe result" do + result = gettext_interpolate(string, :a => "foo") + result.should == "Hello foo" + result.should_not be_html_safe + end + + it "should give an unsafe result" do + result = gettext_interpolate(string, :a => "foo".html_safe) + result.should == "Hello foo" + result.should_not be_html_safe + end + end + + context "html safe string" do + let(:string) { "Hello {{a}}".html_safe } + + it "should quote the input if it's unsafe" do + result = gettext_interpolate(string, :a => "foo&") + result.should == "Hello foo&" + result.should be_html_safe + end + + it "should not quote the input if it's safe" do + result = gettext_interpolate(string, :a => "foo&".html_safe) + result.should == "Hello foo&" + result.should be_html_safe + end + end +end |