From 44e9fd5144984d833c6927c7dcd8a79868af2c07 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 30 Sep 2023 21:23:57 +0200 Subject: [PATCH 1/4] Define doXInclude for XSLTProcessor, and test the property This was added in 8d1427dd98, but never defined on the stub. It was more or less fine when dynamic properties were not deprecated, but now they throw a deprecation warning. To fix it, define on the stub. This should also help discoverability of the functionality. --- ext/xsl/php_xsl.stub.php | 3 ++ ext/xsl/php_xsl_arginfo.h | 8 +++++- ext/xsl/tests/xinclude/data.xml | 4 +++ ext/xsl/tests/xinclude/xinclude.phpt | 41 ++++++++++++++++++++++++++++ ext/xsl/tests/xinclude/xincluded.xml | 2 ++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 ext/xsl/tests/xinclude/data.xml create mode 100644 ext/xsl/tests/xinclude/xinclude.phpt create mode 100644 ext/xsl/tests/xinclude/xincluded.xml diff --git a/ext/xsl/php_xsl.stub.php b/ext/xsl/php_xsl.stub.php index 4bba5beae8c5..a20cb513c683 100644 --- a/ext/xsl/php_xsl.stub.php +++ b/ext/xsl/php_xsl.stub.php @@ -71,6 +71,9 @@ class XSLTProcessor { + /** @var bool */ + public $doXInclude; + /** * @param DOMDocument|SimpleXMLElement $stylesheet * @tentative-return-type diff --git a/ext/xsl/php_xsl_arginfo.h b/ext/xsl/php_xsl_arginfo.h index aaa8531496a3..c9a9d63d6304 100644 --- a/ext/xsl/php_xsl_arginfo.h +++ b/ext/xsl/php_xsl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 606e6ceba2381588b28e25e140fbcfec8a4dbe84 */ + * Stub hash: 6e083062ab3fc6c48bffdc16b41e071c0848c275 */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XSLTProcessor_importStylesheet, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, stylesheet, IS_OBJECT, 0) @@ -113,5 +113,11 @@ static zend_class_entry *register_class_XSLTProcessor(void) INIT_CLASS_ENTRY(ce, "XSLTProcessor", class_XSLTProcessor_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); + zval property_doXInclude_default_value; + ZVAL_NULL(&property_doXInclude_default_value); + zend_string *property_doXInclude_name = zend_string_init("doXInclude", sizeof("doXInclude") - 1, 1); + zend_declare_typed_property(class_entry, property_doXInclude_name, &property_doXInclude_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_NONE(0)); + zend_string_release(property_doXInclude_name); + return class_entry; } diff --git a/ext/xsl/tests/xinclude/data.xml b/ext/xsl/tests/xinclude/data.xml new file mode 100644 index 000000000000..7c2ef1f6bff3 --- /dev/null +++ b/ext/xsl/tests/xinclude/data.xml @@ -0,0 +1,4 @@ + + + + diff --git a/ext/xsl/tests/xinclude/xinclude.phpt b/ext/xsl/tests/xinclude/xinclude.phpt new file mode 100644 index 000000000000..33f9565bcf81 --- /dev/null +++ b/ext/xsl/tests/xinclude/xinclude.phpt @@ -0,0 +1,41 @@ +--TEST-- +doXInclude +--EXTENSIONS-- +xsl +dom +--FILE-- +loadXML(''); + +$xsl = new DOMDocument; +$xsl->loadXML(<< + + + + + + + +XML); + +$xslt = new XSLTProcessor; +$xslt->doXInclude = true; +$xslt->importStylesheet($xsl); +echo $xslt->transformToXml($xml); + +$xslt = new XSLTProcessor; +$xslt->doXInclude = false; +$xslt->importStylesheet($xsl); +echo $xslt->transformToXml($xml); + +?> +--EXPECT-- + +This is sample content + + diff --git a/ext/xsl/tests/xinclude/xincluded.xml b/ext/xsl/tests/xinclude/xincluded.xml new file mode 100644 index 000000000000..a7f1c25add68 --- /dev/null +++ b/ext/xsl/tests/xinclude/xincluded.xml @@ -0,0 +1,2 @@ + +This is sample content \ No newline at end of file From ed6521143be8672b54268f50eee08fd66289a82b Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 30 Sep 2023 22:09:04 +0200 Subject: [PATCH 2/4] Define cloneDocument for XSLTProcessor, and test the property This was introduced in 5c039bbad9, but never defined on the stub. It was more or less fine when dynamic properties were not deprecated, but now they throw a deprecation warning. To fix it, define on the stub. This should also help discoverability of the functionality. --- ext/xsl/php_xsl.stub.php | 3 +++ ext/xsl/php_xsl_arginfo.h | 8 +++++- ext/xsl/tests/cloneDocument.phpt | 45 ++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 ext/xsl/tests/cloneDocument.phpt diff --git a/ext/xsl/php_xsl.stub.php b/ext/xsl/php_xsl.stub.php index a20cb513c683..93b2a635c4e3 100644 --- a/ext/xsl/php_xsl.stub.php +++ b/ext/xsl/php_xsl.stub.php @@ -74,6 +74,9 @@ class XSLTProcessor /** @var bool */ public $doXInclude; + /** @var bool */ + public $cloneDocument; + /** * @param DOMDocument|SimpleXMLElement $stylesheet * @tentative-return-type diff --git a/ext/xsl/php_xsl_arginfo.h b/ext/xsl/php_xsl_arginfo.h index c9a9d63d6304..d99bc9bd8aa9 100644 --- a/ext/xsl/php_xsl_arginfo.h +++ b/ext/xsl/php_xsl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 6e083062ab3fc6c48bffdc16b41e071c0848c275 */ + * Stub hash: 7c64af970cee927db5225081afb16f853c53aab1 */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XSLTProcessor_importStylesheet, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, stylesheet, IS_OBJECT, 0) @@ -119,5 +119,11 @@ static zend_class_entry *register_class_XSLTProcessor(void) zend_declare_typed_property(class_entry, property_doXInclude_name, &property_doXInclude_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_NONE(0)); zend_string_release(property_doXInclude_name); + zval property_cloneDocument_default_value; + ZVAL_NULL(&property_cloneDocument_default_value); + zend_string *property_cloneDocument_name = zend_string_init("cloneDocument", sizeof("cloneDocument") - 1, 1); + zend_declare_typed_property(class_entry, property_cloneDocument_name, &property_cloneDocument_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_NONE(0)); + zend_string_release(property_cloneDocument_name); + return class_entry; } diff --git a/ext/xsl/tests/cloneDocument.phpt b/ext/xsl/tests/cloneDocument.phpt new file mode 100644 index 000000000000..0af1da4c6e35 --- /dev/null +++ b/ext/xsl/tests/cloneDocument.phpt @@ -0,0 +1,45 @@ +--TEST-- +cloneDocument +--EXTENSIONS-- +xsl +dom +--FILE-- +loadXML('hello'); + +function test() { + global $xml; + $xml->documentElement->firstChild->textContent = "bye"; +} + +$xsl = new DOMDocument; +$xsl->loadXML(<< + + + + + + +XML); + +$xslt = new XSLTProcessor; +$xslt->registerPHPFunctions(); +$xslt->cloneDocument = true; +$xslt->importStylesheet($xsl); +echo $xslt->transformToXml($xml); + +$xslt = new XSLTProcessor; +$xslt->registerPHPFunctions(); +$xslt->cloneDocument = false; +$xslt->importStylesheet($xsl); +echo $xslt->transformToXml($xml); + +?> +--EXPECT-- + +hello + +bye From 27198c2cf2a0d7db373868e76b1d823dafa00221 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 1 Oct 2023 00:06:05 +0200 Subject: [PATCH 3/4] Address review feedback --- UPGRADING | 2 ++ ext/xsl/php_xsl.stub.php | 6 ++---- ext/xsl/php_xsl_arginfo.h | 10 +++++----- ext/xsl/xsltprocessor.c | 14 ++++---------- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/UPGRADING b/UPGRADING index d8327ed93348..e7ddbae6b2cd 100644 --- a/UPGRADING +++ b/UPGRADING @@ -43,6 +43,8 @@ PHP 8.4 UPGRADE NOTES . XSLTProcessor::setParameter() will now throw a ValueError when its arguments contain null bytes. This never actually worked correctly in the first place, which is why it throws an exception nowadays. + . The typed properties XSLTProcessor::$cloneDocument and + XSLTProcessor::$doXInclude are now declared. ======================================== 2. New Features diff --git a/ext/xsl/php_xsl.stub.php b/ext/xsl/php_xsl.stub.php index 93b2a635c4e3..55ad36150bf6 100644 --- a/ext/xsl/php_xsl.stub.php +++ b/ext/xsl/php_xsl.stub.php @@ -71,11 +71,9 @@ class XSLTProcessor { - /** @var bool */ - public $doXInclude; + public bool $doXInclude = false; - /** @var bool */ - public $cloneDocument; + public bool $cloneDocument = false; /** * @param DOMDocument|SimpleXMLElement $stylesheet diff --git a/ext/xsl/php_xsl_arginfo.h b/ext/xsl/php_xsl_arginfo.h index d99bc9bd8aa9..d1c23d4bfe6f 100644 --- a/ext/xsl/php_xsl_arginfo.h +++ b/ext/xsl/php_xsl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7c64af970cee927db5225081afb16f853c53aab1 */ + * Stub hash: 5518a63a4adec49c81e650d620ce2dbce41d8d65 */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XSLTProcessor_importStylesheet, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, stylesheet, IS_OBJECT, 0) @@ -114,15 +114,15 @@ static zend_class_entry *register_class_XSLTProcessor(void) class_entry = zend_register_internal_class_ex(&ce, NULL); zval property_doXInclude_default_value; - ZVAL_NULL(&property_doXInclude_default_value); + ZVAL_FALSE(&property_doXInclude_default_value); zend_string *property_doXInclude_name = zend_string_init("doXInclude", sizeof("doXInclude") - 1, 1); - zend_declare_typed_property(class_entry, property_doXInclude_name, &property_doXInclude_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_NONE(0)); + zend_declare_typed_property(class_entry, property_doXInclude_name, &property_doXInclude_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); zend_string_release(property_doXInclude_name); zval property_cloneDocument_default_value; - ZVAL_NULL(&property_cloneDocument_default_value); + ZVAL_FALSE(&property_cloneDocument_default_value); zend_string *property_cloneDocument_name = zend_string_init("cloneDocument", sizeof("cloneDocument") - 1, 1); - zend_declare_typed_property(class_entry, property_cloneDocument_name, &property_cloneDocument_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_NONE(0)); + zend_declare_typed_property(class_entry, property_cloneDocument_name, &property_cloneDocument_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); zend_string_release(property_cloneDocument_name); return class_entry; diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c index fb607c40b1a1..25a30b64c027 100644 --- a/ext/xsl/xsltprocessor.c +++ b/ext/xsl/xsltprocessor.c @@ -313,11 +313,8 @@ PHP_METHOD(XSLTProcessor, importStylesheet) intern = Z_XSL_P(id); member = ZSTR_INIT_LITERAL("cloneDocument", 0); - cloneDocu = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_IS, NULL, &rv); - if (Z_TYPE_P(cloneDocu) != IS_NULL) { - convert_to_long(cloneDocu); - clone_docu = Z_LVAL_P(cloneDocu); - } + cloneDocu = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_R, NULL, &rv); + clone_docu = zend_is_true(cloneDocu); zend_string_release_ex(member, 0); if (clone_docu == 0) { /* check if the stylesheet is using xsl:key, if yes, we have to clone the document _always_ before a transformation */ @@ -415,11 +412,8 @@ static xmlDocPtr php_xsl_apply_stylesheet(zval *id, xsl_object *intern, xsltStyl } member = ZSTR_INIT_LITERAL("doXInclude", 0); - doXInclude = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_IS, NULL, &rv); - if (Z_TYPE_P(doXInclude) != IS_NULL) { - convert_to_long(doXInclude); - ctxt->xinclude = Z_LVAL_P(doXInclude); - } + doXInclude = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_R, NULL, &rv); + ctxt->xinclude = zend_is_true(doXInclude); zend_string_release_ex(member, 0); secPrefsValue = intern->securityPrefs; From 272fdaa904d25430ee007c5376bb464410213a0d Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 1 Oct 2023 13:22:14 +0200 Subject: [PATCH 4/4] EOL before EOF --- ext/xsl/tests/xinclude/xincluded.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/xsl/tests/xinclude/xincluded.xml b/ext/xsl/tests/xinclude/xincluded.xml index a7f1c25add68..cdca87bad7e3 100644 --- a/ext/xsl/tests/xinclude/xincluded.xml +++ b/ext/xsl/tests/xinclude/xincluded.xml @@ -1,2 +1,2 @@ -This is sample content \ No newline at end of file +This is sample content