Skip to content

Commit 5224614

Browse files
committed
Fixed bug #67081 DOMDocumentType->internalSubset returns entire DOCTYPE tag, not only the subset
1 parent 1d34d82 commit 5224614

File tree

7 files changed

+92
-13
lines changed

7 files changed

+92
-13
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2014, PHP 5.4.29
44

5+
- DOM:
6+
. Fixed bug #67081 (DOMDocumentType->internalSubset returns entire DOCTYPE tag,
7+
not only the subset). (Anatol)
8+
59
?? ??? 2014, PHP 5.4.28
610

711
- Core:

ext/dom/documenttype.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ int dom_documenttype_internal_subset_read(dom_object *obj, zval **retval TSRMLS_
188188
{
189189

190190
xmlDtdPtr dtdptr;
191-
xmlDtd *intsubset;
192-
xmlOutputBuffer *buff = NULL;
191+
xmlDtdPtr intsubset;
193192

194193
dtdptr = (xmlDtdPtr) dom_object_get_node(obj);
195194

@@ -200,22 +199,37 @@ int dom_documenttype_internal_subset_read(dom_object *obj, zval **retval TSRMLS_
200199

201200
ALLOC_ZVAL(*retval);
202201

203-
if (dtdptr->doc != NULL && ((intsubset = dtdptr->doc->intSubset) != NULL)) {
204-
buff = xmlAllocOutputBuffer(NULL);
205-
if (buff != NULL) {
206-
xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL);
207-
xmlOutputBufferFlush(buff);
202+
if (dtdptr->doc != NULL && ((intsubset = xmlGetIntSubset(dtdptr->doc)) != NULL) && intsubset->children != NULL) {
203+
smart_str ret_buf = {0};
204+
xmlNodePtr cur = intsubset->children;
205+
206+
while (cur != NULL) {
207+
xmlOutputBuffer *buff = xmlAllocOutputBuffer(NULL);
208+
209+
if (buff != NULL) {
210+
xmlNodeDumpOutput (buff, NULL, cur, 0, 0, NULL);
211+
xmlOutputBufferFlush(buff);
212+
208213
#ifdef LIBXML2_NEW_BUFFER
209-
ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff), xmlOutputBufferGetSize(buff), 1);
214+
smart_str_appendl(ret_buf, xmlOutputBufferGetContent(buff), xmlOutputBufferGetSize(buff));
210215
#else
211-
ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1);
216+
smart_str_appendl(&ret_buf, buff->buffer->content, buff->buffer->use);
212217
#endif
213-
(void)xmlOutputBufferClose(buff);
218+
219+
(void)xmlOutputBufferClose(buff);
220+
}
221+
222+
cur = cur->next;
223+
}
224+
225+
if (ret_buf.len) {
226+
ZVAL_STRINGL(*retval, ret_buf.c, ret_buf.len, 1);
227+
smart_str_free(&ret_buf);
214228
return SUCCESS;
215229
}
216230
}
217231

218-
ZVAL_EMPTY_STRING(*retval);
232+
ZVAL_NULL(*retval);
219233

220234
return SUCCESS;
221235

ext/dom/tests/DOMDocumentType_basic_001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ print 'notation: '.$notation->nodeName."\n";
4343
publicId: -//OASIS//DTD DocBook XML//EN
4444
systemId: docbookx.dtd
4545
name: chapter
46-
internalSubset: <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML//EN" "docbookx.dtd">
46+
internalSubset:
4747
entity: logo
48-
notation: gif
48+
notation: gif

ext/dom/tests/bug67081.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Bug #67081 DOMDocumentType->internalSubset returns entire DOCTYPE tag, not only the subset
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
$domDocument = new DOMDocument();
10+
$domDocument->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug67081_0.xml");
11+
var_dump($domDocument->doctype->internalSubset);
12+
13+
$domDocument = new DOMDocument();
14+
$domDocument->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug67081_1.xml");
15+
var_dump($domDocument->doctype->internalSubset);
16+
17+
$domDocument = new DOMDocument();
18+
$domDocument->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug67081_2.xml");
19+
var_dump($domDocument->doctype->internalSubset);
20+
21+
$domDocument = new DOMDocument();
22+
$domDocument->load(dirname(__FILE__) . DIRECTORY_SEPARATOR . "dom.xml");
23+
var_dump($domDocument->doctype->internalSubset);
24+
?>
25+
===DONE===
26+
--EXPECT--
27+
string(19) "<!ELEMENT a EMPTY>
28+
"
29+
string(38) "<!ELEMENT a EMPTY>
30+
<!ELEMENT b EMPTY>
31+
"
32+
NULL
33+
string(277) "<!ENTITY % incent SYSTEM "dom.ent">
34+
<!ENTITY amp "&#38;#38;">
35+
<!ENTITY gt "&#62;">
36+
<!ENTITY % coreattrs "title CDATA #IMPLIED">
37+
<!ENTITY % attrs "%coreattrs;">
38+
<!ATTLIST foo bar CDATA #IMPLIED>
39+
<!ELEMENT foo (#PCDATA)>
40+
<!ELEMENT root (foo)+>
41+
<!ATTLIST th title CDATA #IMPLIED>
42+
"
43+
===DONE===

ext/dom/tests/bug67081_0.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE a [
3+
<!ELEMENT a EMPTY>
4+
]>
5+
<a></a>
6+

ext/dom/tests/bug67081_1.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE a [
3+
<!ELEMENT a EMPTY>
4+
<!ELEMENT b EMPTY>
5+
]>
6+
<a></a>
7+

ext/dom/tests/bug67081_2.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4+
<a></a>
5+

0 commit comments

Comments
 (0)