Skip to content

Commit

Permalink
Merge pull request #265 from flavorjones/flavorjones-test-with-old-no…
Browse files Browse the repository at this point in the history
…kogiri

don't define HTML5::Document and HTML5::DocumentFragment if HTML5 isn't supported
  • Loading branch information
flavorjones authored May 10, 2023
2 parents a9b51f4 + d2744d4 commit f874431
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/loofah.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def html5_support?
require_relative "loofah/html4/document"
require_relative "loofah/html4/document_fragment"

if Nokogiri.respond_to?(:uses_gumbo?) && Nokogiri.uses_gumbo?
if Loofah.html5_support?
require_relative "loofah/html5/document"
require_relative "loofah/html5/document_fragment"
end
Expand Down Expand Up @@ -123,19 +123,19 @@ def scrub_html5_fragment(string_or_io, method)
end
else
def html5_document(*args, &block)
raise NotImplementedError, "HTML5 is not supported by your version of Nokogiri"
raise NotImplementedError, "Loofah::HTML5 is not supported by your version of Nokogiri"
end

def html5_fragment(*args, &block)
raise NotImplementedError, "HTML5 is not supported by your version of Nokogiri"
raise NotImplementedError, "Loofah::HTML5 is not supported by your version of Nokogiri"
end

def scrub_html5_document(string_or_io, method)
raise NotImplementedError, "HTML5 is not supported by your version of Nokogiri"
raise NotImplementedError, "Loofah::HTML5 is not supported by your version of Nokogiri"
end

def scrub_html5_fragment(string_or_io, method)
raise NotImplementedError, "HTML5 is not supported by your version of Nokogiri"
raise NotImplementedError, "Loofah::HTML5 is not supported by your version of Nokogiri"
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/unit/test_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class UnitTestApi < Loofah::TestCase
assert_raises(NotImplementedError) { Loofah.html5_fragment(html) }
assert_raises(NotImplementedError) { Loofah.scrub_html5_fragment(html, :strip) }
end

it "does not implement classes" do
assert_raises(NameError) { Loofah::HTML5::Document }
assert_raises(NameError) { Loofah::HTML5::DocumentFragment }
end
end
end

Expand Down

0 comments on commit f874431

Please sign in to comment.