From 2852b92dca14f5bc53e2403ced4e16d5fdaa4452 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Mon, 8 Jan 2024 13:54:56 -0800 Subject: [PATCH] Fix broken DTD name handling --- ext/libxml/ruby_xml_dtd.c | 13 ++++++++----- test/test_document.rb | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ext/libxml/ruby_xml_dtd.c b/ext/libxml/ruby_xml_dtd.c index 127d28ad..46dbe5fd 100644 --- a/ext/libxml/ruby_xml_dtd.c +++ b/ext/libxml/ruby_xml_dtd.c @@ -132,8 +132,8 @@ static VALUE rxml_dtd_type(VALUE self) * * * The first usage creates a DTD from a string and requires 1 parameter. * * The second usage loads and parses an external DTD and requires 2 parameters. - * * The third usage creates a new internal or external DTD and requires 3 parameters and 2 optional parameters. - * It then attaches the DTD to the specified document if it is not nil + * * The third usage creates a new internal or external DTD and requires 2 parameters and 3 optional parameters. + * The DTD is then attached to the specified document if it is not nil. * * Parameters: * @@ -160,7 +160,7 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self) xmlDocPtr xdoc = NULL; VALUE name, doc, internal; - rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal); + rb_scan_args(argc, argv, "23", &external, &system, &name, &doc, &internal); Check_Type(external, T_STRING); xpublic = (const xmlChar*) StringValuePtr(external); @@ -168,8 +168,11 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self) Check_Type(system, T_STRING); xsystem = (const xmlChar*) StringValuePtr(system); - Check_Type(name, T_STRING); - xname = (const xmlChar*) StringValuePtr(name); + if (name != Qnil) + { + Check_Type(name, T_STRING); + xname = (const xmlChar*)StringValuePtr(name); + } if (doc != Qnil) { diff --git a/test/test_document.rb b/test/test_document.rb index e8ab840f..57ce5582 100644 --- a/test/test_document.rb +++ b/test/test_document.rb @@ -82,7 +82,7 @@ def test_doc_node_type_name def test_xhtml doc = LibXML::XML::Document.new assert(!doc.xhtml?) - LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true + LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true) assert(doc.xhtml?) end