Skip to content

Commit 2852b92

Browse files
committed
Fix broken DTD name handling
1 parent e38d3b0 commit 2852b92

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

ext/libxml/ruby_xml_dtd.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ static VALUE rxml_dtd_type(VALUE self)
132132
*
133133
* * The first usage creates a DTD from a string and requires 1 parameter.
134134
* * The second usage loads and parses an external DTD and requires 2 parameters.
135-
* * The third usage creates a new internal or external DTD and requires 3 parameters and 2 optional parameters.
136-
* It then attaches the DTD to the specified document if it is not nil
135+
* * The third usage creates a new internal or external DTD and requires 2 parameters and 3 optional parameters.
136+
* The DTD is then attached to the specified document if it is not nil.
137137
*
138138
* Parameters:
139139
*
@@ -160,16 +160,19 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
160160
xmlDocPtr xdoc = NULL;
161161

162162
VALUE name, doc, internal;
163-
rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal);
163+
rb_scan_args(argc, argv, "23", &external, &system, &name, &doc, &internal);
164164

165165
Check_Type(external, T_STRING);
166166
xpublic = (const xmlChar*) StringValuePtr(external);
167167

168168
Check_Type(system, T_STRING);
169169
xsystem = (const xmlChar*) StringValuePtr(system);
170170

171-
Check_Type(name, T_STRING);
172-
xname = (const xmlChar*) StringValuePtr(name);
171+
if (name != Qnil)
172+
{
173+
Check_Type(name, T_STRING);
174+
xname = (const xmlChar*)StringValuePtr(name);
175+
}
173176

174177
if (doc != Qnil)
175178
{

test/test_document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_doc_node_type_name
8282
def test_xhtml
8383
doc = LibXML::XML::Document.new
8484
assert(!doc.xhtml?)
85-
LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
85+
LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true)
8686
assert(doc.xhtml?)
8787
end
8888

0 commit comments

Comments
 (0)