test/test_sanitize_css.rb in sanitize-3.1.2 vs test/test_sanitize_css.rb in sanitize-4.0.0

- old
+ new

@@ -218,11 +218,11 @@ end end end end - describe 'bugs' do + describe 'functionality' do before do @default = Sanitize::CSS.new @relaxed = Sanitize::CSS.new(Sanitize::Config::RELAXED[:css]) end @@ -233,17 +233,98 @@ css = %[ @media (max-width: 720px) { p.foo > .bar { float: right; width: expression(body.scrollLeft + 50 + 'px'); } #baz { color: green; } + + @media (orientation: portrait) { + #baz { color: red; } + } } ].strip @relaxed.stylesheet(css).must_equal %[ @media (max-width: 720px) { p.foo > .bar { float: right; } #baz { color: green; } + + @media (orientation: portrait) { + #baz { color: red; } + } } ].strip + end + + it 'should parse @page rules properly' do + css = %[ + @page { margin: 2cm } /* All margins set to 2cm */ + + @page :right { + @top-center { content: "Preliminary edition" } + @bottom-center { content: counter(page) } + } + + @page { + size: 8.5in 11in; + margin: 10%; + + @top-left { + content: "Hamlet"; + } + @top-right { + content: "Page " counter(page); + } + } + ].strip + + @relaxed.stylesheet(css).must_equal css + end + + describe ":at_rules" do + it "should remove blockless at-rules that aren't whitelisted" do + css = %[ + @charset 'utf-8'; + @import url('foo.css'); + .foo { color: green; } + ].strip + + @relaxed.stylesheet(css).strip.must_equal %[ + .foo { color: green; } + ].strip + end + + describe "when blockless at-rules are whitelisted" do + before do + @scss = Sanitize::CSS.new(Sanitize::Config.merge(Sanitize::Config::RELAXED[:css], { + :at_rules => ['charset', 'import'] + })) + end + + it "should not remove them" do + css = %[ + @charset 'utf-8'; + @import url('foo.css'); + .foo { color: green; } + ].strip + + @scss.stylesheet(css).must_equal %[ + @charset 'utf-8'; + @import url('foo.css'); + .foo { color: green; } + ].strip + end + + it "should remove them if they have invalid blocks" do + css = %[ + @charset { color: green } + @import { color: green } + .foo { color: green; } + ].strip + + @scss.stylesheet(css).strip.must_equal %[ + .foo { color: green; } + ].strip + end + end end end end