diff --git a/actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb b/actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb index f6c13885ff8617df4f84e696694da91fb25d64cc..251820b81b873d1845705c15b4697d5a161be93c 100644 --- a/actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb +++ b/actionview/lib/action_view/helpers/sanitize_helper/sanitizers.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/class/attribute' +require 'active_support/core_ext/object/blank' require 'active_support/deprecation' require 'action_view/helpers/sanitize_helper/scrubbers' @@ -25,7 +26,7 @@ def remove_xpaths(html, xpaths) class FullSanitizer < Sanitizer def sanitize(html, options = {}) return unless html - return html if html.empty? + return html if html.blank? Loofah.fragment(html).tap do |fragment| remove_xpaths(fragment, XPATHS_TO_REMOVE) @@ -51,6 +52,7 @@ def initialize def sanitize(html, options = {}) return unless html + return html if html.blank? loofah_fragment = Loofah.fragment(html) diff --git a/actionview/test/template/sanitizers_test.rb b/actionview/test/template/sanitizers_test.rb index dc511b6ec26c05158a53863e1b8978fb19c649b9..48079bf0600e3693684781c589c9f7f9eb9766a1 100644 --- a/actionview/test/template/sanitizers_test.rb +++ b/actionview/test/template/sanitizers_test.rb @@ -98,7 +98,7 @@ def test_strip_tags assert_equal("This is a test.", sanitizer.sanitize("

This is a test.

")) assert_equal("", sanitizer.sanitize("<<")) - + assert_equal("This is a test.", sanitizer.sanitize("This is a test.")) assert_equal "This has a here.", sanitizer.sanitize("This has a here.") @@ -219,7 +219,7 @@ def test_should_allow_custom_tags_with_custom_attributes def test_should_raise_argument_error_if_tags_is_not_enumerable sanitizer = ActionView::WhiteListSanitizer.new e = assert_raise(ArgumentError) do - sanitizer.sanitize('', :tags => 'foo') + sanitizer.sanitize('some html', :tags => 'foo') end assert_equal "You should pass :tags as an Enumerable", e.message @@ -228,7 +228,7 @@ def test_should_raise_argument_error_if_tags_is_not_enumerable def test_should_raise_argument_error_if_attributes_is_not_enumerable sanitizer = ActionView::WhiteListSanitizer.new e = assert_raise(ArgumentError) do - sanitizer.sanitize('', :attributes => 'foo') + sanitizer.sanitize('some html', :attributes => 'foo') end assert_equal "You should pass :attributes as an Enumerable", e.message @@ -242,7 +242,7 @@ def scrub(node); node.name = 'h1'; end end assert_raise Loofah::ScrubberNotFound do - sanitizer.sanitize('', :scrubber => scrubber) + sanitizer.sanitize('some html', :scrubber => scrubber) end end