# encoding: utf-8
require_relative 'common'
describe 'Sanitize' do
describe 'initializer' do
it 'should not modify a transformers array in the given config' do
transformers = [
lambda {}
]
Sanitize.new({ :transformers => transformers })
transformers.length.must_equal(1)
end
end
describe 'instance methods' do
before do
@s = Sanitize.new
end
describe '#document' do
before do
@s = Sanitize.new(:elements => ['html'])
end
it 'should sanitize an HTML document' do
@s.document('Lorem ipsum dolor sit
amet ')
.must_equal "Lorem ipsum dolor sit amet alert(\"hello world\");\n"
end
it 'should not modify the input string' do
input = 'foo'
@s.document(input)
input.must_equal('foo')
end
it 'should not choke on frozen documents' do
@s.document('foo'.freeze).must_equal "foo\n"
end
end
describe '#fragment' do
it 'should sanitize an HTML fragment' do
@s.fragment('Lorem ipsum dolor sit
amet ')
.must_equal 'Lorem ipsum dolor sit amet alert("hello world");'
end
it 'should not modify the input string' do
input = 'foo'
@s.fragment(input)
input.must_equal 'foo'
end
it 'should not choke on fragments containing or