diff options
author | Timm <kaspth@gmail.com> | 2013-08-09 18:20:31 +0200 |
---|---|---|
committer | Timm <kaspth@gmail.com> | 2014-06-16 21:04:02 +0200 |
commit | 945e7f529e1c9cb2690a2bbe3374f883771a2cd1 (patch) | |
tree | fcf27bb07fac08650d9385f0dce2c1c7d45de6ce /actionview | |
parent | f428aeaa197aa5ec686d2f7103c0aadc883774d2 (diff) | |
download | rails-945e7f529e1c9cb2690a2bbe3374f883771a2cd1.tar.gz rails-945e7f529e1c9cb2690a2bbe3374f883771a2cd1.tar.bz2 rails-945e7f529e1c9cb2690a2bbe3374f883771a2cd1.zip |
Refactored remove_xpaths to use duck typing and read better.
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb b/actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb index 99d4e64346..0e2e1826ec 100644 --- a/actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb +++ b/actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb @@ -10,11 +10,12 @@ module ActionView end def remove_xpaths(html, xpaths) - html = Loofah.fragment(html) unless html.is_a? Nokogiri::XML::DocumentFragment - xpaths.each do |xpath| - html.xpath(xpath).each { |subtree| subtree.remove } + if html.respond_to?(:xpath) + xpaths.each { |xpath| html.xpath(xpath).remove } + html.to_s + else + remove_xpaths(Loofah.fragment(html), xpaths) end - html.to_s end end |