]> granicus.if.org Git - php/commitdiff
Fixed bug #67081 DOMDocumentType->internalSubset returns entire DOCTYPE tag, not...
authorAnatol Belski <ab@php.net>
Wed, 16 Apr 2014 12:13:45 +0000 (14:13 +0200)
committerAnatol Belski <ab@php.net>
Wed, 16 Apr 2014 12:13:45 +0000 (14:13 +0200)
NEWS
ext/dom/documenttype.c
ext/dom/tests/DOMDocumentType_basic_001.phpt
ext/dom/tests/bug67081.phpt [new file with mode: 0644]
ext/dom/tests/bug67081_0.xml [new file with mode: 0644]
ext/dom/tests/bug67081_1.xml [new file with mode: 0644]
ext/dom/tests/bug67081_2.xml [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 83852f58429bfc632334dace66f8e1bdce59334a..4c2a97e72210dab04c2fc9902739ec1d022f5d3c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2014, PHP 5.4.29
 
+- DOM:
+  . Fixed bug #67081 (DOMDocumentType->internalSubset returns entire DOCTYPE tag,
+    not only the subset). (Anatol)
+
 ?? ??? 2014, PHP 5.4.28
 
 - Core:
index a94cc31d74c7a357953b9d99e04d796eeb8484f7..406e468ac8a1de72c8ef56129acecf9ae88ce2d7 100644 (file)
@@ -188,8 +188,7 @@ int dom_documenttype_internal_subset_read(dom_object *obj, zval **retval TSRMLS_
 {
 
        xmlDtdPtr dtdptr;
-       xmlDtd *intsubset;
-       xmlOutputBuffer *buff = NULL;
+       xmlDtdPtr intsubset;
 
        dtdptr = (xmlDtdPtr) dom_object_get_node(obj);
 
@@ -200,22 +199,37 @@ int dom_documenttype_internal_subset_read(dom_object *obj, zval **retval TSRMLS_
 
        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;
 
index 8991ed97d47ad65d0cf9de428b8e3f6c8e73b747..6648a146ff6e6ad85b3d08ba98d907af73a0378c 100644 (file)
@@ -43,6 +43,6 @@ print 'notation: '.$notation->nodeName."\n";
 publicId: -//OASIS//DTD DocBook XML//EN
 systemId: docbookx.dtd
 name: chapter
-internalSubset: <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML//EN" "docbookx.dtd">
+internalSubset: 
 entity: logo
-notation: gif
\ No newline at end of file
+notation: gif
diff --git a/ext/dom/tests/bug67081.phpt b/ext/dom/tests/bug67081.phpt
new file mode 100644 (file)
index 0000000..56c2c8e
--- /dev/null
@@ -0,0 +1,43 @@
+--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;#38;">
+<!ENTITY gt "&#62;">
+<!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===
diff --git a/ext/dom/tests/bug67081_0.xml b/ext/dom/tests/bug67081_0.xml
new file mode 100644 (file)
index 0000000..604eea5
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<!DOCTYPE a [
+   <!ELEMENT a EMPTY>
+]>
+<a></a>
+
diff --git a/ext/dom/tests/bug67081_1.xml b/ext/dom/tests/bug67081_1.xml
new file mode 100644 (file)
index 0000000..7ae542e
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<!DOCTYPE a [
+   <!ELEMENT a EMPTY>
+   <!ELEMENT b EMPTY>
+]>
+<a></a>
+
diff --git a/ext/dom/tests/bug67081_2.xml b/ext/dom/tests/bug67081_2.xml
new file mode 100644 (file)
index 0000000..c10af09
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<a></a>
+