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.
This commit is contained in:
Niels Dossche 2023-07-25 21:09:47 +02:00
parent abb1d2e824
commit bf4e7bd3ed
4 changed files with 126 additions and 49 deletions

2
NEWS
View File

@ -12,6 +12,8 @@ PHP NEWS
(nielsdos)
. Fix DOMCharacterData::replaceWith() with itself. (nielsdos)
. Fix empty argument cases for DOMParentNode methods. (nielsdos)
. Fixed bug GH-11791 (Wrong default value of DOMDocument::xmlStandalone).
(nielsdos)
- FFI:
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)

View File

@ -187,7 +187,7 @@ int dom_document_standalone_read(dom_object *obj, zval *retval)
return FAILURE;
}
ZVAL_BOOL(retval, docp->standalone);
ZVAL_BOOL(retval, docp->standalone > 0);
return SUCCESS;
}

View File

@ -12,53 +12,89 @@ XML;
$d = new domdocument;
$d->dynamicProperty = new stdclass;
$d->loadXML($xml);
print_r($d);
var_dump($d);
?>
--EXPECTF--
DOMDocument Object
(
[config] =>
[dynamicProperty] => stdClass Object
(
)
[doctype] =>
[implementation] => (object value omitted)
[documentElement] => (object value omitted)
[actualEncoding] =>
[encoding] =>
[xmlEncoding] =>
[standalone] => 1
[xmlStandalone] => 1
[version] => 1.0
[xmlVersion] => 1.0
[strictErrorChecking] => 1
[documentURI] => %s
[formatOutput] =>
[validateOnParse] =>
[resolveExternals] =>
[preserveWhiteSpace] => 1
[recover] =>
[substituteEntities] =>
[firstElementChild] => (object value omitted)
[lastElementChild] => (object value omitted)
[childElementCount] => 1
[nodeName] => #document
[nodeValue] =>
[nodeType] => 9
[parentNode] =>
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] =>
[nextSibling] =>
[attributes] =>
[ownerDocument] =>
[namespaceURI] =>
[prefix] =>
[localName] =>
[baseURI] => %s
[textContent] =>
--EXPECT--
object(DOMDocument)#1 (39) {
["config"]=>
NULL
["dynamicProperty"]=>
object(stdClass)#2 (0) {
}
["doctype"]=>
NULL
["implementation"]=>
string(22) "(object value omitted)"
["documentElement"]=>
string(22) "(object value omitted)"
["actualEncoding"]=>
NULL
["encoding"]=>
NULL
["xmlEncoding"]=>
NULL
["standalone"]=>
bool(false)
["xmlStandalone"]=>
bool(false)
["version"]=>
string(3) "1.0"
["xmlVersion"]=>
string(3) "1.0"
["strictErrorChecking"]=>
bool(true)
["documentURI"]=>
string(46) "/run/media/niels/MoreData/php-src-FOR-MERGING/"
["formatOutput"]=>
bool(false)
["validateOnParse"]=>
bool(false)
["resolveExternals"]=>
bool(false)
["preserveWhiteSpace"]=>
bool(true)
["recover"]=>
bool(false)
["substituteEntities"]=>
bool(false)
["firstElementChild"]=>
string(22) "(object value omitted)"
["lastElementChild"]=>
string(22) "(object value omitted)"
["childElementCount"]=>
int(1)
["nodeName"]=>
string(9) "#document"
["nodeValue"]=>
NULL
["nodeType"]=>
int(9)
["parentNode"]=>
NULL
["childNodes"]=>
string(22) "(object value omitted)"
["firstChild"]=>
string(22) "(object value omitted)"
["lastChild"]=>
string(22) "(object value omitted)"
["previousSibling"]=>
NULL
["nextSibling"]=>
NULL
["attributes"]=>
NULL
["ownerDocument"]=>
NULL
["namespaceURI"]=>
NULL
["prefix"]=>
string(0) ""
["localName"]=>
NULL
["baseURI"]=>
string(46) "/run/media/niels/MoreData/php-src-FOR-MERGING/"
["textContent"]=>
string(12) "
foobar
)
"
}

View File

@ -0,0 +1,39 @@
--TEST--
GH-11791 (Wrong default value of DOMDocument.xmlStandalone)
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument();
$doc->loadXML('<root/>');
var_dump($doc->xmlStandalone);
$doc->xmlStandalone = true;
var_dump($doc->xmlStandalone);
$doc = new DOMDocument();
$doc->loadXML('<?xml version="1.0"?><root/>');
var_dump($doc->xmlStandalone);
$doc->xmlStandalone = true;
var_dump($doc->xmlStandalone);
$doc = new DOMDocument();
$doc->loadXML('<?xml version="1.0" standalone="no"?><root/>');
var_dump($doc->xmlStandalone);
$doc->xmlStandalone = true;
var_dump($doc->xmlStandalone);
$doc = new DOMDocument();
$doc->loadXML('<?xml version="1.0" standalone="yes"?><root/>');
var_dump($doc->xmlStandalone);
$doc->xmlStandalone = false;
var_dump($doc->xmlStandalone);
?>
--EXPECT--
bool(false)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
bool(true)
bool(false)