Skip to content

Commit 9dc6010

Browse files
committed
Fix RelaxNG factories to raise on parse failure instead of wrapping NULL.
1 parent 5086cec commit 9dc6010

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

ext/libxml/ruby_xml_relaxng.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ static VALUE rxml_relaxng_init_from_uri(VALUE class, VALUE uri)
6363
xrelaxng = xmlRelaxNGParse(xparser);
6464
xmlRelaxNGFreeParserCtxt(xparser);
6565

66+
if (!xrelaxng)
67+
rxml_raise(xmlGetLastError());
68+
6669
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
6770
}
6871

@@ -84,6 +87,9 @@ static VALUE rxml_relaxng_init_from_document(VALUE class, VALUE document)
8487
xrelaxng = xmlRelaxNGParse(xparser);
8588
xmlRelaxNGFreeParserCtxt(xparser);
8689

90+
if (!xrelaxng)
91+
rxml_raise(xmlGetLastError());
92+
8793
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
8894
}
8995

@@ -104,6 +110,9 @@ static VALUE rxml_relaxng_init_from_string(VALUE self, VALUE relaxng_str)
104110
xrelaxng = xmlRelaxNGParse(xparser);
105111
xmlRelaxNGFreeParserCtxt(xparser);
106112

113+
if (!xrelaxng)
114+
rxml_raise(xmlGetLastError());
115+
107116
return TypedData_Wrap_Struct(cXMLRelaxNG, &rxml_relaxng_data_type, xrelaxng);
108117
}
109118

test/test_relaxng.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def test_valid
2626
assert(@doc.validate_relaxng(relaxng))
2727
end
2828

29+
def test_parse_failure_raises
30+
assert_raises(LibXML::XML::Error) do
31+
LibXML::XML::RelaxNG.new("<invalid/>")
32+
end
33+
end
34+
2935
def test_invalid
3036
new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
3137
@doc.root << new_node

0 commit comments

Comments
 (0)