{
xmlDtdPtr dtdptr;
- xmlDtd *intsubset;
- xmlOutputBuffer *buff = NULL;
+ xmlDtdPtr intsubset;
dtdptr = (xmlDtdPtr) dom_object_get_node(obj);
ALLOC_ZVAL(*retval);
- if (dtdptr->doc != NULL && ((intsubset = dtdptr->doc->intSubset) != NULL)) {
- buff = xmlAllocOutputBuffer(NULL);
- if (buff != NULL) {
- xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL);
- xmlOutputBufferFlush(buff);
+ if (dtdptr->doc != NULL && ((intsubset = xmlGetIntSubset(dtdptr->doc)) != NULL) && intsubset->children != NULL) {
+ smart_str ret_buf = {0};
+ xmlNodePtr cur = intsubset->children;
+
+ while (cur != NULL) {
+ xmlOutputBuffer *buff = xmlAllocOutputBuffer(NULL);
+
+ if (buff != NULL) {
+ xmlNodeDumpOutput (buff, NULL, cur, 0, 0, NULL);
+ xmlOutputBufferFlush(buff);
+
#ifdef LIBXML2_NEW_BUFFER
- ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff), xmlOutputBufferGetSize(buff), 1);
+ smart_str_appendl(ret_buf, xmlOutputBufferGetContent(buff), xmlOutputBufferGetSize(buff));
#else
- ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1);
+ smart_str_appendl(&ret_buf, buff->buffer->content, buff->buffer->use);
#endif
- (void)xmlOutputBufferClose(buff);
+
+ (void)xmlOutputBufferClose(buff);
+ }
+
+ cur = cur->next;
+ }
+
+ if (ret_buf.len) {
+ ZVAL_STRINGL(*retval, ret_buf.c, ret_buf.len, 1);
+ smart_str_free(&ret_buf);
return SUCCESS;
}
}
- ZVAL_EMPTY_STRING(*retval);
+ ZVAL_NULL(*retval);
return SUCCESS;
--- /dev/null
+--TEST--
+Bug #67081 DOMDocumentType->internalSubset returns entire DOCTYPE tag, not only the subset
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+?>
+--FILE--
+<?php
+ $domDocument = new DOMDocument();
+ $domDocument->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug67081_0.xml");
+ var_dump($domDocument->doctype->internalSubset);
+
+ $domDocument = new DOMDocument();
+ $domDocument->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug67081_1.xml");
+ var_dump($domDocument->doctype->internalSubset);
+
+ $domDocument = new DOMDocument();
+ $domDocument->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug67081_2.xml");
+ var_dump($domDocument->doctype->internalSubset);
+
+ $domDocument = new DOMDocument();
+ $domDocument->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . "dom.xml");
+ var_dump($domDocument->doctype->internalSubset);
+?>
+===DONE===
+--EXPECT--
+string(19) "<!ELEMENT a EMPTY>
+"
+string(38) "<!ELEMENT a EMPTY>
+<!ELEMENT b EMPTY>
+"
+NULL
+string(277) "<!ENTITY % incent SYSTEM "dom.ent">
+<!ENTITY amp "&#38;">
+<!ENTITY gt ">">
+<!ENTITY % coreattrs "title CDATA #IMPLIED">
+<!ENTITY % attrs "%coreattrs;">
+<!ATTLIST foo bar CDATA #IMPLIED>
+<!ELEMENT foo (#PCDATA)>
+<!ELEMENT root (foo)+>
+<!ATTLIST th title CDATA #IMPLIED>
+"
+===DONE===