Skip to content

Commit bf4e7bd

Browse files
committed
Fix GH-11791: Wrong default value of DOMDocument::xmlStandalone
At one point this was changed from a bool to an int in libxml2, with negative values meaning it is unspecified. Because it is cast to a bool this therefore returned true instead of the expected false. Closes GH-11793.
1 parent abb1d2e commit bf4e7bd

File tree

4 files changed

+126
-49
lines changed

4 files changed

+126
-49
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212
(nielsdos)
1313
. Fix DOMCharacterData::replaceWith() with itself. (nielsdos)
1414
. Fix empty argument cases for DOMParentNode methods. (nielsdos)
15+
. Fixed bug GH-11791 (Wrong default value of DOMDocument::xmlStandalone).
16+
(nielsdos)
1517

1618
- FFI:
1719
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)

ext/dom/document.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int dom_document_standalone_read(dom_object *obj, zval *retval)
187187
return FAILURE;
188188
}
189189

190-
ZVAL_BOOL(retval, docp->standalone);
190+
ZVAL_BOOL(retval, docp->standalone > 0);
191191
return SUCCESS;
192192
}
193193

ext/dom/tests/domobject_debug_handler.phpt

Lines changed: 84 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,89 @@ XML;
1212
$d = new domdocument;
1313
$d->dynamicProperty = new stdclass;
1414
$d->loadXML($xml);
15-
print_r($d);
15+
var_dump($d);
1616
?>
17-
--EXPECTF--
18-
DOMDocument Object
19-
(
20-
[config] =>
21-
[dynamicProperty] => stdClass Object
22-
(
23-
)
24-
25-
[doctype] =>
26-
[implementation] => (object value omitted)
27-
[documentElement] => (object value omitted)
28-
[actualEncoding] =>
29-
[encoding] =>
30-
[xmlEncoding] =>
31-
[standalone] => 1
32-
[xmlStandalone] => 1
33-
[version] => 1.0
34-
[xmlVersion] => 1.0
35-
[strictErrorChecking] => 1
36-
[documentURI] => %s
37-
[formatOutput] =>
38-
[validateOnParse] =>
39-
[resolveExternals] =>
40-
[preserveWhiteSpace] => 1
41-
[recover] =>
42-
[substituteEntities] =>
43-
[firstElementChild] => (object value omitted)
44-
[lastElementChild] => (object value omitted)
45-
[childElementCount] => 1
46-
[nodeName] => #document
47-
[nodeValue] =>
48-
[nodeType] => 9
49-
[parentNode] =>
50-
[childNodes] => (object value omitted)
51-
[firstChild] => (object value omitted)
52-
[lastChild] => (object value omitted)
53-
[previousSibling] =>
54-
[nextSibling] =>
55-
[attributes] =>
56-
[ownerDocument] =>
57-
[namespaceURI] =>
58-
[prefix] =>
59-
[localName] =>
60-
[baseURI] => %s
61-
[textContent] =>
17+
--EXPECT--
18+
object(DOMDocument)#1 (39) {
19+
["config"]=>
20+
NULL
21+
["dynamicProperty"]=>
22+
object(stdClass)#2 (0) {
23+
}
24+
["doctype"]=>
25+
NULL
26+
["implementation"]=>
27+
string(22) "(object value omitted)"
28+
["documentElement"]=>
29+
string(22) "(object value omitted)"
30+
["actualEncoding"]=>
31+
NULL
32+
["encoding"]=>
33+
NULL
34+
["xmlEncoding"]=>
35+
NULL
36+
["standalone"]=>
37+
bool(false)
38+
["xmlStandalone"]=>
39+
bool(false)
40+
["version"]=>
41+
string(3) "1.0"
42+
["xmlVersion"]=>
43+
string(3) "1.0"
44+
["strictErrorChecking"]=>
45+
bool(true)
46+
["documentURI"]=>
47+
string(46) "/run/media/niels/MoreData/php-src-FOR-MERGING/"
48+
["formatOutput"]=>
49+
bool(false)
50+
["validateOnParse"]=>
51+
bool(false)
52+
["resolveExternals"]=>
53+
bool(false)
54+
["preserveWhiteSpace"]=>
55+
bool(true)
56+
["recover"]=>
57+
bool(false)
58+
["substituteEntities"]=>
59+
bool(false)
60+
["firstElementChild"]=>
61+
string(22) "(object value omitted)"
62+
["lastElementChild"]=>
63+
string(22) "(object value omitted)"
64+
["childElementCount"]=>
65+
int(1)
66+
["nodeName"]=>
67+
string(9) "#document"
68+
["nodeValue"]=>
69+
NULL
70+
["nodeType"]=>
71+
int(9)
72+
["parentNode"]=>
73+
NULL
74+
["childNodes"]=>
75+
string(22) "(object value omitted)"
76+
["firstChild"]=>
77+
string(22) "(object value omitted)"
78+
["lastChild"]=>
79+
string(22) "(object value omitted)"
80+
["previousSibling"]=>
81+
NULL
82+
["nextSibling"]=>
83+
NULL
84+
["attributes"]=>
85+
NULL
86+
["ownerDocument"]=>
87+
NULL
88+
["namespaceURI"]=>
89+
NULL
90+
["prefix"]=>
91+
string(0) ""
92+
["localName"]=>
93+
NULL
94+
["baseURI"]=>
95+
string(46) "/run/media/niels/MoreData/php-src-FOR-MERGING/"
96+
["textContent"]=>
97+
string(12) "
6298
foobar
63-
64-
)
99+
"
100+
}

ext/dom/tests/gh11791.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
GH-11791 (Wrong default value of DOMDocument.xmlStandalone)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument();
8+
$doc->loadXML('<root/>');
9+
var_dump($doc->xmlStandalone);
10+
$doc->xmlStandalone = true;
11+
var_dump($doc->xmlStandalone);
12+
13+
$doc = new DOMDocument();
14+
$doc->loadXML('<?xml version="1.0"?><root/>');
15+
var_dump($doc->xmlStandalone);
16+
$doc->xmlStandalone = true;
17+
var_dump($doc->xmlStandalone);
18+
19+
$doc = new DOMDocument();
20+
$doc->loadXML('<?xml version="1.0" standalone="no"?><root/>');
21+
var_dump($doc->xmlStandalone);
22+
$doc->xmlStandalone = true;
23+
var_dump($doc->xmlStandalone);
24+
25+
$doc = new DOMDocument();
26+
$doc->loadXML('<?xml version="1.0" standalone="yes"?><root/>');
27+
var_dump($doc->xmlStandalone);
28+
$doc->xmlStandalone = false;
29+
var_dump($doc->xmlStandalone);
30+
?>
31+
--EXPECT--
32+
bool(false)
33+
bool(true)
34+
bool(false)
35+
bool(true)
36+
bool(false)
37+
bool(true)
38+
bool(true)
39+
bool(false)

0 commit comments

Comments
 (0)