Skip to content

Commit 8c3be62

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.
1 parent abb1d2e commit 8c3be62

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

ext/dom/document.c

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ DOMDocument Object
2828
[actualEncoding] =>
2929
[encoding] =>
3030
[xmlEncoding] =>
31-
[standalone] => 1
32-
[xmlStandalone] => 1
31+
[standalone] =>
32+
[xmlStandalone] =>
3333
[version] => 1.0
3434
[xmlVersion] => 1.0
3535
[strictErrorChecking] => 1

ext/dom/tests/gh11791.phpt

+39
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)