Skip to content

Commit

Permalink
Returning anything other than a Hash or nil from a transformer will n…
Browse files Browse the repository at this point in the history
…ow raise a meaningful Sanitize::Error exception rather than an unintended NameError. Closes #15
  • Loading branch information
rgrove committed Jan 23, 2010
1 parent 317b406 commit 0a8e5f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Sanitize History
================================================================================

Version 1.2.1 (git)
* Returning anything other than a Hash or nil from a transformer will now
raise a meaningful Sanitize::Error exception rather than an unintended
NameError.

Version 1.2.0 (2010-01-17)
* Requires Nokogiri ~> 1.4.1.
* Added support for transformers, which allow you to filter and alter nodes
Expand Down
2 changes: 2 additions & 0 deletions lib/sanitize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,6 @@ def transform_element!(node)

return output
end

class Error < StandardError; end
end
6 changes: 6 additions & 0 deletions test/spec_sanitize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,10 @@

Sanitize.clean!(input, :transformers => youtube).should.equal(output)
end

should 'raise Sanitize::Error when a transformer returns something silly' do
should.raise(Sanitize::Error) do
Sanitize.clean!('<b>foo</b>', :transformers => lambda { 'hello' })
end
end
end

0 comments on commit 0a8e5f2

Please sign in to comment.