From 945e7f529e1c9cb2690a2bbe3374f883771a2cd1 Mon Sep 17 00:00:00 2001 From: Timm Date: Fri, 9 Aug 2013 18:20:31 +0200 Subject: Refactored remove_xpaths to use duck typing and read better. --- actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'actionview/lib') 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 -- cgit v1.2.3