Skip to content

Commit

Permalink
test: update tests to reflect upstream libxml2 entity references (#3182)
Browse files Browse the repository at this point in the history
**What problem is this PR intended to solve?**

GNOME/libxml2@b717abdd makes undeclared entities a warning where it used
to be an error


**Does this change affect the behavior of either the C or the Java
implementations?**

I'm opting to leave the JRuby implementation as-is. We can change it
later if anybody requests it.
  • Loading branch information
flavorjones committed Apr 24, 2024
2 parents c2daff1 + 982bb22 commit 9b3f287
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions test/xml/test_entity_reference.rb
Expand Up @@ -163,7 +163,9 @@ def setup
doc = @parser.parse(xml, path, &:default_xml)

assert_kind_of Nokogiri::XML::EntityReference, doc.xpath("//body").first.children.first
if Nokogiri.uses_libxml?
if Nokogiri.uses_libxml?(">= 2.13.0") # gnome/libxml2@b717abdd
assert_equal ["5:14: WARNING: Entity 'bar' not defined"], doc.errors.map(&:to_s)
elsif Nokogiri.uses_libxml?
assert_equal ["5:14: ERROR: Entity 'bar' not defined"], doc.errors.map(&:to_s)
end
end
Expand All @@ -184,11 +186,11 @@ def setup

assert_kind_of Nokogiri::XML::EntityReference, doc.xpath("//body").first.children.first

expected = if Nokogiri.uses_libxml?(">= 2.13")
expected = if Nokogiri.uses_libxml?(">= 2.13") # many gnome/libxml2 changes made in 2023-12
[
"2:49: WARNING: failed to load \"http://foo.bar.com/\": Attempt to load network entity",
"ERROR: Attempt to load network entity: http://foo.bar.com/",
"4:14: ERROR: Entity 'bar' not defined",
"4:14: WARNING: Entity 'bar' not defined", # gnome/libxml2@b717abdd
]
elsif Nokogiri.uses_libxml?
[
Expand Down Expand Up @@ -218,16 +220,20 @@ def setup
xml = File.read(xml_document)
@parser.parse(xml)

refute_nil @parser.document.errors
actual = if Nokogiri.uses_libxml?(">= 2.13.0") # gnome/libxml2@b717abdd
@parser.document.warnings
else
@parser.document.errors
end

errors = @parser.document.errors.map { |e| e.to_s.strip }
actual = actual.map { |e| e.to_s.strip }
expected = if truffleruby_system_libraries?
["error_func: %s"]
else
["Entity 'bar' not defined"]
end

assert_equal(expected, errors)
assert_equal(expected, actual)
end

test_relative_and_absolute_path :test_more_sax_entity_reference do
Expand All @@ -241,16 +247,23 @@ def setup
XML
@parser.parse(xml)

refute_nil @parser.document.errors
actual = if Nokogiri.uses_libxml?(">= 2.13.0") # gnome/libxml2@b717abdd
@parser.document.warnings
else
@parser.document.errors
end

refute_nil(actual)
refute_empty(actual)

errors = @parser.document.errors.map { |e| e.to_s.strip }
actual = actual.map { |e| e.to_s.strip }
expected = if truffleruby_system_libraries?
["error_func: %s"]
else
["Entity 'bar' not defined"]
end

assert_equal(expected, errors)
assert_equal(expected, actual)
end
end

Expand Down

0 comments on commit 9b3f287

Please sign in to comment.