Permalink
Browse files

Merge pull request #58 from fabrikagency/master

:remove_contents option accepts an array of symbols.
  • Loading branch information...
2 parents 4925ac8 + 1c881e9 commit c45162d8a012cac3362ade7fadc3737095cb1a50 @rgrove committed Aug 22, 2012
Showing with 6 additions and 2 deletions.
  1. +1 −1 lib/sanitize/transformers/clean_element.rb
  2. +5 −1 test/test_sanitize.rb
@@ -14,7 +14,7 @@ def initialize(config)
@whitespace_elements = Set.new(config[:whitespace_elements])
if config[:remove_contents].is_a?(Array)
- @remove_element_contents.merge(config[:remove_contents])
+ @remove_element_contents.merge(config[:remove_contents].map(&:to_s))
else
@remove_all_contents = !!config[:remove_contents]
end
View
@@ -311,10 +311,14 @@
Sanitize.clean('foo bar <div>baz<span>quux</span></div>', :remove_contents => true).must_equal('foo bar ')
end
- it 'should remove the contents of specified nodes when :remove_contents is an Array of element names' do
+ it 'should remove the contents of specified nodes when :remove_contents is an Array of element names as strings' do
Sanitize.clean('foo bar <div>baz<span>quux</span><script>alert("hello!");</script></div>', :remove_contents => ['script', 'span']).must_equal('foo bar baz ')
end
+ it 'should remove the contents of specified nodes when :remove_contents is an Array of element names as symbols' do
+ Sanitize.clean('foo bar <div>baz<span>quux</span><script>alert("hello!");</script></div>', :remove_contents => [:script, :span]).must_equal('foo bar baz ')
+ end
+
it 'should support encodings other than utf-8' do
html = 'foo&nbsp;bar'
Sanitize.clean(html).must_equal("foo\302\240bar")

0 comments on commit c45162d

Please sign in to comment.