@@ -7,6 +7,34 @@ def setup
77 assert @xsd = Nokogiri ::XML ::Schema ( File . read ( PO_SCHEMA_FILE ) )
88 end
99
10+ def test_segv
11+ skip ( "Pure Java version shouldn't have this bug" ) unless Nokogiri . uses_libxml?
12+
13+ # This is a test for a workaround for a bug in LibXML2. The upstream
14+ # bug is here: https://gitlab.gnome.org/GNOME/libxml2/issues/148
15+ # Schema creation can result in dangling pointers. If no nodes have
16+ # been exposed, then it should be fine to create a schema. If nodes
17+ # have been exposed to Ruby, then we need to make sure they won't be
18+ # freed out from under us.
19+ doc = <<~doc
20+ <?xml version="1.0" encoding="UTF-8" ?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
21+ <xs:element name="foo" type="xs:string"/></xs:schema>
22+ doc
23+
24+ # This is OK, no nodes have been exposed
25+ xsd_doc = Nokogiri ::XML ( doc )
26+ assert Nokogiri ::XML ::Schema . from_document ( xsd_doc )
27+
28+ # This is not OK, nodes have been exposed to Ruby
29+ xsd_doc = Nokogiri ::XML ( doc )
30+ node = xsd_doc . root . children . find ( &:blank? ) # Finds a node
31+
32+ ex = assert_raise ( ArgumentError ) do
33+ Nokogiri ::XML ::Schema . from_document ( xsd_doc )
34+ end
35+ assert_match ( /blank nodes/ , ex . message )
36+ end
37+
1038 def test_schema_from_document
1139 doc = Nokogiri ::XML ( File . open ( PO_SCHEMA_FILE ) )
1240 assert doc
0 commit comments