From 3bb56ae418dd1da15f3a23bb34a9b29f8927ec16 Mon Sep 17 00:00:00 2001
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date: Fri, 6 Oct 2023 17:42:47 +0200
Subject: [PATCH] Add missing properties to xsl stub (#12334)
* 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.
* 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.
---
UPGRADING | 2 ++
ext/xsl/php_xsl.stub.php | 4 +++
ext/xsl/php_xsl_arginfo.h | 14 ++++++++-
ext/xsl/tests/cloneDocument.phpt | 45 ++++++++++++++++++++++++++++
ext/xsl/tests/xinclude/data.xml | 4 +++
ext/xsl/tests/xinclude/xinclude.phpt | 41 +++++++++++++++++++++++++
ext/xsl/tests/xinclude/xincluded.xml | 2 ++
ext/xsl/xsltprocessor.c | 14 +++------
8 files changed, 115 insertions(+), 11 deletions(-)
create mode 100644 ext/xsl/tests/cloneDocument.phpt
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/UPGRADING b/UPGRADING
index 1f8e7ad3aa7..04217a0bde8 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 4bba5beae8c..55ad36150bf 100644
--- a/ext/xsl/php_xsl.stub.php
+++ b/ext/xsl/php_xsl.stub.php
@@ -71,6 +71,10 @@ const LIBEXSLT_DOTTED_VERSION = UNKNOWN;
class XSLTProcessor
{
+ public bool $doXInclude = false;
+
+ public bool $cloneDocument = false;
+
/**
* @param DOMDocument|SimpleXMLElement $stylesheet
* @tentative-return-type
diff --git a/ext/xsl/php_xsl_arginfo.h b/ext/xsl/php_xsl_arginfo.h
index aaa8531496a..d1c23d4bfe6 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: 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)
@@ -113,5 +113,17 @@ 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_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_MASK(MAY_BE_BOOL));
+ zend_string_release(property_doXInclude_name);
+
+ zval 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_MASK(MAY_BE_BOOL));
+ 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 00000000000..0af1da4c6e3
--- /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
diff --git a/ext/xsl/tests/xinclude/data.xml b/ext/xsl/tests/xinclude/data.xml
new file mode 100644
index 00000000000..7c2ef1f6bff
--- /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 00000000000..33f9565bcf8
--- /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 00000000000..cdca87bad7e
--- /dev/null
+++ b/ext/xsl/tests/xinclude/xincluded.xml
@@ -0,0 +1,2 @@
+
+This is sample content
diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c
index 23e431d5e37..0e20375a162 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;