Skip to content

Commit

Permalink
ci: upstream libxml2 fixed conditional html comments
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Aug 15, 2022
1 parent afe634a commit 55ef19e
Showing 1 changed file with 53 additions and 12 deletions.
65 changes: 53 additions & 12 deletions test/html4/test_comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,8 @@ class TestComment < Nokogiri::TestCase
let(:body) { doc.at_css("body") }
let(:subject) { doc.at_css("div#under-test") }

if Nokogiri.uses_libxml?("<=2.9.13") && !upstream_xmlsoft?
it "ignores up to the next '>'" do # NON-COMPLIANT
assert_equal 2, body.children.length
assert_equal body.children[0], subject
assert_equal 1, subject.children.length
assert_predicate subject.children[0], :text?
assert_equal "inner content", subject.children[0].content
assert_predicate body.children[1], :text?
assert_equal "-->hello", body.children[1].content
end
elsif Nokogiri.uses_libxml?
it "parses as pcdata" do # NON-COMPLIANT
if Nokogiri.uses_libxml?("=2.9.14")
it "parses as PCDATA" do # NON-COMPLIANT
assert_equal 1, body.children.length
assert_equal subject, body.children.first

Expand All @@ -203,6 +193,16 @@ class TestComment < Nokogiri::TestCase
assert_equal("-->hello", child.content)
end
end
elsif Nokogiri.uses_libxml? # before or after 2.9.14
it "ignores up to the next '>'" do # NON-COMPLIANT
assert_equal 2, body.children.length
assert_equal body.children[0], subject
assert_equal 1, subject.children.length
assert_predicate subject.children[0], :text?
assert_equal "inner content", subject.children[0].content
assert_predicate body.children[1], :text?
assert_equal "-->hello", body.children[1].content
end
end

if Nokogiri.jruby?
Expand All @@ -217,6 +217,47 @@ class TestComment < Nokogiri::TestCase
end
end

# conditional HTML comments, variation of the above
# https://gitlab.gnome.org/GNOME/libxml2/-/issues/380
describe "conditional HTML comments" do
let(:html) { "<html><body><div id=under-test><![if foo]><div id=do-i-exist>inner content</div><![endif]></div></body></html>" }

let(:doc) { Nokogiri::HTML4(html) }
let(:body) { doc.at_css("body") }
let(:subject) { doc.at_css("div#under-test") }

if Nokogiri.uses_libxml?("=2.9.14")
it "parses the <! tags as PCDATA" do
assert_equal(1, body.children.length)
assert_equal(subject, body.children.first)

assert_equal(3, subject.children.length)
subject.children[0].tap do |child|
assert_predicate(child, :text?)
assert_equal("<![if foo]>", child.content)
end
subject.children[1].tap do |child|
assert_predicate(child, :element?)
assert_equal("div", child.name)
assert_equal("do-i-exist", child["id"])
end
subject.children[2].tap do |child|
assert_predicate(child, :text?)
assert_equal("<![endif]>", child.content)
end
end
else # libxml before or after 2.9.14, or jruby
it "drops the <! tags" do
assert_equal(1, body.children.length)
assert_equal(subject, body.children.first)

assert_equal(1, subject.children.length)
assert_equal("div", subject.children.first.name)
assert_equal("do-i-exist", subject.children.first["id"])
end
end
end

# https://html.spec.whatwg.org/multipage/parsing.html#parse-error-nested-comment
#
# This error occurs if the parser encounters a nested comment
Expand Down

0 comments on commit 55ef19e

Please sign in to comment.