From 8c3be623ba0c7146a19bc3acd8f552191309cc46 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Tue, 25 Jul 2023 21:09:47 +0200 Subject: [PATCH] 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. --- ext/dom/document.c | 2 +- ext/dom/tests/domobject_debug_handler.phpt | 4 +-- ext/dom/tests/gh11791.phpt | 39 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 ext/dom/tests/gh11791.phpt diff --git a/ext/dom/document.c b/ext/dom/document.c index 71e12b6e7a95d..e0eeb80fcb7ec 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -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; } diff --git a/ext/dom/tests/domobject_debug_handler.phpt b/ext/dom/tests/domobject_debug_handler.phpt index 8dbaa61a16545..c305c215c3d3b 100644 --- a/ext/dom/tests/domobject_debug_handler.phpt +++ b/ext/dom/tests/domobject_debug_handler.phpt @@ -28,8 +28,8 @@ DOMDocument Object [actualEncoding] => [encoding] => [xmlEncoding] => - [standalone] => 1 - [xmlStandalone] => 1 + [standalone] => + [xmlStandalone] => [version] => 1.0 [xmlVersion] => 1.0 [strictErrorChecking] => 1 diff --git a/ext/dom/tests/gh11791.phpt b/ext/dom/tests/gh11791.phpt new file mode 100644 index 0000000000000..22d94b51312a7 --- /dev/null +++ b/ext/dom/tests/gh11791.phpt @@ -0,0 +1,39 @@ +--TEST-- +GH-11791 (Wrong default value of DOMDocument.xmlStandalone) +--EXTENSIONS-- +dom +--FILE-- +loadXML(''); +var_dump($doc->xmlStandalone); +$doc->xmlStandalone = true; +var_dump($doc->xmlStandalone); + +$doc = new DOMDocument(); +$doc->loadXML(''); +var_dump($doc->xmlStandalone); +$doc->xmlStandalone = true; +var_dump($doc->xmlStandalone); + +$doc = new DOMDocument(); +$doc->loadXML(''); +var_dump($doc->xmlStandalone); +$doc->xmlStandalone = true; +var_dump($doc->xmlStandalone); + +$doc = new DOMDocument(); +$doc->loadXML(''); +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)