com php-src: Fixed bug #67081 DOMDocumentType->internalSubset returns entire DOCTYPE tag, not only the subset: NEWS ext/dom/documenttype.c
ext/dom/tests/DOMDocumentType_basic_001.phpt ext/ dom/tests/bug67081.phpt ext/dom/tests/bug67 081_0.xml ext/dom/tests/bug67081_1 .xml
ext/dom/tests/bug67081_2.xml
| From: | Anatol Belski | Date: | Wed, 16 Apr 2014 12:13:45 +0000 |
| Subject: | com php-src: Fixed bug #67081 DOMDocumentType->internalSubset returns entire DOCTYPE tag, not only the subset: NEWS ext/dom/documenttype.c ext/dom/tests/DOMDocumentType_basic_001.phpt ext/ dom/tests/bug67081.phpt ext/dom/tests/bug67 081_0.xml ext/dom/tests/bug67081_1 .xml ext/dom/tests/bug67081_2.xml |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-76920@lists.php.net to get a copy of this message | ||
Commit: 5224614f23eff18419f2c5489bebe60562e0ce2a
Author: Anatol Belski <ab@php.net> Wed, 16 Apr 2014 14:13:45 +0200
Parents: 1d34d822315a97bb7d3eeb3b9e75f34807ac4a12
Branches: PHP-5.4 PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5224614f23eff18419f2c5489bebe60562e0ce2a
Log:
Fixed bug #67081 DOMDocumentType->internalSubset returns entire DOCTYPE tag, not only the subset
Bugs:
https://bugs.php.net/67081
Changed paths:
M NEWS
M ext/dom/documenttype.c
M ext/dom/tests/DOMDocumentType_basic_001.phpt
A ext/dom/tests/bug67081.phpt
A ext/dom/tests/bug67081_0.xml
A ext/dom/tests/bug67081_1.xml
A ext/dom/tests/bug67081_2.xml
Diff:
diff --git a/NEWS b/NEWS
index 83852f5..4c2a97e 100644
--- 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:
diff --git a/ext/dom/documenttype.c b/ext/dom/documenttype.c
index a94cc31..406e468 100644
--- a/ext/dom/documenttype.c
+++ b/ext/dom/documenttype.c
@@ -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;
diff --git a/ext/dom/tests/DOMDocumentType_basic_001.phpt
b/ext/dom/tests/DOMDocumentType_basic_001.phpt
index 8991ed9..6648a14 100644
--- a/ext/dom/tests/DOMDocumentType_basic_001.phpt
+++ b/ext/dom/tests/DOMDocumentType_basic_001.phpt
@@ -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
index 0000000..56c2c8e
--- /dev/null
+++ b/ext/dom/tests/bug67081.phpt
@@ -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;">
+<!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===
diff --git a/ext/dom/tests/bug67081_0.xml b/ext/dom/tests/bug67081_0.xml
new file mode 100644
index 0000000..604eea5
--- /dev/null
+++ b/ext/dom/tests/bug67081_0.xml
@@ -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
index 0000000..7ae542e
--- /dev/null
+++ b/ext/dom/tests/bug67081_1.xml
@@ -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
index 0000000..c10af09
--- /dev/null
+++ b/ext/dom/tests/bug67081_2.xml
@@ -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>
+