diff options
author | Matthew Landauer <matthew@openaustralia.org> | 2013-01-15 13:41:31 +1100 |
---|---|---|
committer | Matthew Landauer <matthew@openaustralia.org> | 2013-01-15 13:41:31 +1100 |
commit | b58df4dcd623044455ae86764c5a9fa1d44ebeaa (patch) | |
tree | 4b0fa175f486f24830182bb88606857b471638bd /spec/lib/i18n_interpolation.rb | |
parent | 01dc6b68ebc2f325cde83b5a6711f19ac78efb47 (diff) |
Fix translations with interpolations to correctly handle safe_html
Diffstat (limited to 'spec/lib/i18n_interpolation.rb')
-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 8c86413ad..3fb72ff03 100644 --- a/spec/lib/i18n_interpolation.rb +++ b/spec/lib/i18n_interpolation.rb @@ -11,5 +11,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 |