Skip to content

Commit 9b3f287

Browse files
authored
test: update tests to reflect upstream libxml2 entity references (#3182)
**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.
2 parents c2daff1 + 982bb22 commit 9b3f287

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

test/xml/test_entity_reference.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ def setup
163163
doc = @parser.parse(xml, path, &:default_xml)
164164

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

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

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

221-
refute_nil @parser.document.errors
223+
actual = if Nokogiri.uses_libxml?(">= 2.13.0") # gnome/libxml2@b717abdd
224+
@parser.document.warnings
225+
else
226+
@parser.document.errors
227+
end
222228

223-
errors = @parser.document.errors.map { |e| e.to_s.strip }
229+
actual = actual.map { |e| e.to_s.strip }
224230
expected = if truffleruby_system_libraries?
225231
["error_func: %s"]
226232
else
227233
["Entity 'bar' not defined"]
228234
end
229235

230-
assert_equal(expected, errors)
236+
assert_equal(expected, actual)
231237
end
232238

233239
test_relative_and_absolute_path :test_more_sax_entity_reference do
@@ -241,16 +247,23 @@ def setup
241247
XML
242248
@parser.parse(xml)
243249

244-
refute_nil @parser.document.errors
250+
actual = if Nokogiri.uses_libxml?(">= 2.13.0") # gnome/libxml2@b717abdd
251+
@parser.document.warnings
252+
else
253+
@parser.document.errors
254+
end
255+
256+
refute_nil(actual)
257+
refute_empty(actual)
245258

246-
errors = @parser.document.errors.map { |e| e.to_s.strip }
259+
actual = actual.map { |e| e.to_s.strip }
247260
expected = if truffleruby_system_libraries?
248261
["error_func: %s"]
249262
else
250263
["Entity 'bar' not defined"]
251264
end
252265

253-
assert_equal(expected, errors)
266+
assert_equal(expected, actual)
254267
end
255268
end
256269

0 commit comments

Comments
 (0)