mirror of
https://github.com/php/php-src.git
synced 2025-08-18 23:18:56 +02:00
add unicode support
registered_phpfunctions hashtable still needs to be handled update tests
This commit is contained in:
parent
aee8e73316
commit
db883a8b9d
3 changed files with 66 additions and 33 deletions
|
@ -11,7 +11,7 @@ function __autoload($className) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$xsl = new DomDocument();
|
$xsl = new DomDocument();
|
||||||
$xsl->loadXML('<?xml version="1.0" encoding="iso-8859-1" ?>
|
$xsl->loadXML(b'<?xml version="1.0" encoding="iso-8859-1" ?>
|
||||||
<xsl:stylesheet version="1.0"
|
<xsl:stylesheet version="1.0"
|
||||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
xmlns:php="http://php.net/xsl">
|
xmlns:php="http://php.net/xsl">
|
||||||
|
@ -20,7 +20,7 @@ xmlns:php="http://php.net/xsl">
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
</xsl:stylesheet>');
|
</xsl:stylesheet>');
|
||||||
$inputdom = new DomDocument();
|
$inputdom = new DomDocument();
|
||||||
$inputdom->loadXML('<?xml version="1.0" encoding="iso-8859-1" ?>
|
$inputdom->loadXML(b'<?xml version="1.0" encoding="iso-8859-1" ?>
|
||||||
<today></today>');
|
<today></today>');
|
||||||
|
|
||||||
$proc = new XsltProcessor();
|
$proc = new XsltProcessor();
|
||||||
|
|
|
@ -32,7 +32,7 @@ $dom = new domDocument();
|
||||||
return $id[0];
|
return $id[0];
|
||||||
} else {
|
} else {
|
||||||
$dom = new domdocument;
|
$dom = new domdocument;
|
||||||
$dom->loadXML("<root>this is from an external DomDocument</root>");
|
$dom->loadXML(b"<root>this is from an external DomDocument</root>");
|
||||||
return $dom->documentElement;
|
return $dom->documentElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,10 +81,11 @@ static char **php_xsl_xslt_make_params(HashTable *parht, int xpath_params TSRMLS
|
||||||
|
|
||||||
int parsize;
|
int parsize;
|
||||||
zval **value;
|
zval **value;
|
||||||
char *xpath_expr, *string_key = NULL;
|
char *xpath_expr;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
char **params = NULL;
|
char **params = NULL;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
zstr string_key = NULL_ZSTR;
|
||||||
|
|
||||||
parsize = (2 * zend_hash_num_elements(parht) + 1) * sizeof(char *);
|
parsize = (2 * zend_hash_num_elements(parht) + 1) * sizeof(char *);
|
||||||
params = (char **)emalloc(parsize);
|
params = (char **)emalloc(parsize);
|
||||||
|
@ -101,7 +102,7 @@ static char **php_xsl_xslt_make_params(HashTable *parht, int xpath_params TSRMLS
|
||||||
} else {
|
} else {
|
||||||
if (Z_TYPE_PP(value) != IS_STRING) {
|
if (Z_TYPE_PP(value) != IS_STRING) {
|
||||||
SEPARATE_ZVAL(value);
|
SEPARATE_ZVAL(value);
|
||||||
convert_to_string(*value);
|
convert_to_string_with_converter(*value, UG(utf8_conv));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!xpath_params) {
|
if (!xpath_params) {
|
||||||
|
@ -110,7 +111,7 @@ static char **php_xsl_xslt_make_params(HashTable *parht, int xpath_params TSRMLS
|
||||||
xpath_expr = estrndup(Z_STRVAL_PP(value), strlen(Z_STRVAL_PP(value)));
|
xpath_expr = estrndup(Z_STRVAL_PP(value), strlen(Z_STRVAL_PP(value)));
|
||||||
}
|
}
|
||||||
if (xpath_expr) {
|
if (xpath_expr) {
|
||||||
params[i++] = string_key;
|
params[i++] = string_key.s;
|
||||||
params[i++] = xpath_expr;
|
params[i++] = xpath_expr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,7 +298,7 @@ static void xsl_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs, int t
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object can not be converted to a XPath-string");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "A PHP Object can not be converted to a XPath-string");
|
||||||
valuePush(ctxt, xmlXPathNewString(""));
|
valuePush(ctxt, xmlXPathNewString(""));
|
||||||
} else {
|
} else {
|
||||||
convert_to_string_ex(&retval);
|
convert_to_string_with_converter(retval, UG(utf8_conv));
|
||||||
valuePush(ctxt, xmlXPathNewString( Z_STRVAL_P(retval)));
|
valuePush(ctxt, xmlXPathNewString( Z_STRVAL_P(retval)));
|
||||||
}
|
}
|
||||||
zval_ptr_dtor(&retval);
|
zval_ptr_dtor(&retval);
|
||||||
|
@ -325,7 +326,7 @@ void xsl_ext_function_object_php(xmlXPathParserContextPtr ctxt, int nargs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* {{{ proto void xsl_xsltprocessor_import_stylesheet(domdocument doc);
|
/* {{{ proto void xsl_xsltprocessor_import_stylesheet(domdocument doc); U
|
||||||
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#
|
||||||
Since:
|
Since:
|
||||||
*/
|
*/
|
||||||
|
@ -494,7 +495,7 @@ static xmlDocPtr php_xsl_apply_stylesheet(zval *id, xsl_object *intern, xsltStyl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* {{{ proto domdocument xsl_xsltprocessor_transform_to_doc(domnode doc);
|
/* {{{ proto domdocument xsl_xsltprocessor_transform_to_doc(domnode doc); U
|
||||||
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#
|
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#
|
||||||
Since:
|
Since:
|
||||||
*/
|
*/
|
||||||
|
@ -526,7 +527,7 @@ PHP_FUNCTION(xsl_xsltprocessor_transform_to_doc)
|
||||||
/* }}} end xsl_xsltprocessor_transform_to_doc */
|
/* }}} end xsl_xsltprocessor_transform_to_doc */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ proto int xsl_xsltprocessor_transform_to_uri(domdocument doc, string uri);
|
/* {{{ proto int xsl_xsltprocessor_transform_to_uri(domdocument doc, string uri); U
|
||||||
*/
|
*/
|
||||||
PHP_FUNCTION(xsl_xsltprocessor_transform_to_uri)
|
PHP_FUNCTION(xsl_xsltprocessor_transform_to_uri)
|
||||||
{
|
{
|
||||||
|
@ -535,13 +536,14 @@ PHP_FUNCTION(xsl_xsltprocessor_transform_to_uri)
|
||||||
xsltStylesheetPtr sheetp;
|
xsltStylesheetPtr sheetp;
|
||||||
int ret, uri_len;
|
int ret, uri_len;
|
||||||
char *uri;
|
char *uri;
|
||||||
|
zend_uchar uri_type;
|
||||||
xsl_object *intern;
|
xsl_object *intern;
|
||||||
|
|
||||||
id = getThis();
|
id = getThis();
|
||||||
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
||||||
sheetp = (xsltStylesheetPtr) intern->ptr;
|
sheetp = (xsltStylesheetPtr) intern->ptr;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "os", &docp, &uri, &uri_len) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ot", &docp, &uri, &uri_len, &uri_type) == FAILURE) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,7 +551,16 @@ PHP_FUNCTION(xsl_xsltprocessor_transform_to_uri)
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
if (newdocp) {
|
if (newdocp) {
|
||||||
|
if (uri_type == IS_UNICODE) {
|
||||||
|
if (php_stream_path_encode(NULL, &uri, &uri_len, (UChar*)uri, uri_len, REPORT_ERRORS, NULL) == FAILURE) {
|
||||||
|
xmlFreeDoc(newdocp);
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
ret = xsltSaveResultToFilename(uri, newdocp, sheetp, 0);
|
ret = xsltSaveResultToFilename(uri, newdocp, sheetp, 0);
|
||||||
|
if (uri_type == IS_UNICODE) {
|
||||||
|
efree(uri);
|
||||||
|
}
|
||||||
xmlFreeDoc(newdocp);
|
xmlFreeDoc(newdocp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,7 +569,7 @@ PHP_FUNCTION(xsl_xsltprocessor_transform_to_uri)
|
||||||
/* }}} end xsl_xsltprocessor_transform_to_uri */
|
/* }}} end xsl_xsltprocessor_transform_to_uri */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ proto string xsl_xsltprocessor_transform_to_xml(domdocument doc);
|
/* {{{ proto string xsl_xsltprocessor_transform_to_xml(domdocument doc); U
|
||||||
*/
|
*/
|
||||||
PHP_FUNCTION(xsl_xsltprocessor_transform_to_xml)
|
PHP_FUNCTION(xsl_xsltprocessor_transform_to_xml)
|
||||||
{
|
{
|
||||||
|
@ -597,7 +608,7 @@ PHP_FUNCTION(xsl_xsltprocessor_transform_to_xml)
|
||||||
/* }}} end xsl_xsltprocessor_transform_to_xml */
|
/* }}} end xsl_xsltprocessor_transform_to_xml */
|
||||||
|
|
||||||
|
|
||||||
/* {{{ proto bool xsl_xsltprocessor_set_parameter(string namespace, mixed name [, string value]);
|
/* {{{ proto bool xsl_xsltprocessor_set_parameter(string namespace, mixed name [, string value]); U
|
||||||
*/
|
*/
|
||||||
PHP_FUNCTION(xsl_xsltprocessor_set_parameter)
|
PHP_FUNCTION(xsl_xsltprocessor_set_parameter)
|
||||||
{
|
{
|
||||||
|
@ -605,35 +616,56 @@ PHP_FUNCTION(xsl_xsltprocessor_set_parameter)
|
||||||
zval *id;
|
zval *id;
|
||||||
zval *array_value, **entry, *new_string;
|
zval *array_value, **entry, *new_string;
|
||||||
xsl_object *intern;
|
xsl_object *intern;
|
||||||
char *string_key, *name, *value, *namespace;
|
char *name, *value, *namespace;
|
||||||
ulong idx;
|
ulong idx;
|
||||||
int string_key_len, namespace_len, name_len, value_len;
|
int namespace_len, name_len, value_len;
|
||||||
|
zstr string_key = NULL_ZSTR;
|
||||||
|
unsigned int string_key_len;
|
||||||
|
|
||||||
DOM_GET_THIS(id);
|
DOM_GET_THIS(id);
|
||||||
|
|
||||||
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sa", &namespace, &namespace_len, &array_value) == SUCCESS) {
|
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s&a", &namespace, &namespace_len, UG(utf8_conv), &array_value) == SUCCESS) {
|
||||||
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value));
|
zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value));
|
||||||
|
|
||||||
while (zend_hash_get_current_data(Z_ARRVAL_P(array_value), (void **)&entry) == SUCCESS) {
|
while (zend_hash_get_current_data(Z_ARRVAL_P(array_value), (void **)&entry) == SUCCESS) {
|
||||||
SEPARATE_ZVAL(entry);
|
int hash_key_type;
|
||||||
convert_to_string_ex(entry);
|
int tmp_len;
|
||||||
|
|
||||||
if (zend_hash_get_current_key_ex(Z_ARRVAL_P(array_value), &string_key, &string_key_len, &idx, 0, NULL) != HASH_KEY_IS_STRING) {
|
hash_key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(array_value), &string_key, &string_key_len, &idx, 0, NULL);
|
||||||
|
if (hash_key_type != HASH_KEY_IS_STRING && hash_key_type != HASH_KEY_IS_UNICODE) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter array");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter array");
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
tmp_len = string_key_len;
|
||||||
|
|
||||||
|
if (hash_key_type == HASH_KEY_IS_UNICODE) {
|
||||||
|
UErrorCode errCode = U_ZERO_ERROR;
|
||||||
|
|
||||||
|
zend_unicode_to_string_ex(UG(utf8_conv), &string_key.s, &tmp_len, string_key.u, string_key_len, &errCode);
|
||||||
|
if (U_FAILURE(errCode)) {
|
||||||
|
efree(string_key.s);
|
||||||
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to convert unicode key to UTF-8");
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SEPARATE_ZVAL(entry);
|
||||||
|
convert_to_string_with_converter(*entry, UG(utf8_conv));
|
||||||
|
|
||||||
ALLOC_ZVAL(new_string);
|
ALLOC_ZVAL(new_string);
|
||||||
ZVAL_ADDREF(*entry);
|
ZVAL_ADDREF(*entry);
|
||||||
COPY_PZVAL_TO_ZVAL(*new_string, *entry);
|
COPY_PZVAL_TO_ZVAL(*new_string, *entry);
|
||||||
|
|
||||||
zend_hash_update(intern->parameter, string_key, string_key_len, &new_string, sizeof(zval*), NULL);
|
zend_hash_update(intern->parameter, string_key.s, tmp_len, &new_string, sizeof(zval*), NULL);
|
||||||
|
if (hash_key_type == HASH_KEY_IS_UNICODE) {
|
||||||
|
efree(string_key.s);
|
||||||
|
}
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(array_value));
|
zend_hash_move_forward(Z_ARRVAL_P(array_value));
|
||||||
}
|
}
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
|
|
||||||
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sss", &namespace, &namespace_len, &name, &name_len, &value, &value_len) == SUCCESS) {
|
} else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s&s&s&", &namespace, &namespace_len, UG(utf8_conv), &name, &name_len, UG(utf8_conv), &value, &value_len, UG(utf8_conv)) == SUCCESS) {
|
||||||
|
|
||||||
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
||||||
|
|
||||||
MAKE_STD_ZVAL(new_string);
|
MAKE_STD_ZVAL(new_string);
|
||||||
|
@ -648,7 +680,7 @@ PHP_FUNCTION(xsl_xsltprocessor_set_parameter)
|
||||||
}
|
}
|
||||||
/* }}} end xsl_xsltprocessor_set_parameter */
|
/* }}} end xsl_xsltprocessor_set_parameter */
|
||||||
|
|
||||||
/* {{{ proto string xsl_xsltprocessor_get_parameter(string namespace, string name);
|
/* {{{ proto string xsl_xsltprocessor_get_parameter(string namespace, string name); U
|
||||||
*/
|
*/
|
||||||
PHP_FUNCTION(xsl_xsltprocessor_get_parameter)
|
PHP_FUNCTION(xsl_xsltprocessor_get_parameter)
|
||||||
{
|
{
|
||||||
|
@ -660,20 +692,21 @@ PHP_FUNCTION(xsl_xsltprocessor_get_parameter)
|
||||||
|
|
||||||
DOM_GET_THIS(id);
|
DOM_GET_THIS(id);
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &namespace, &namespace_len, &name, &name_len) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&s&", &namespace, &namespace_len, UG(utf8_conv), &name, &name_len, UG(utf8_conv)) == FAILURE) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
||||||
if ( zend_hash_find(intern->parameter, name, name_len + 1, (void**) &value) == SUCCESS) {
|
if ( zend_hash_find(intern->parameter, name, name_len + 1, (void**) &value) == SUCCESS) {
|
||||||
convert_to_string_ex(value);
|
convert_to_string_with_converter(*value, UG(utf8_conv));
|
||||||
RETVAL_STRING(Z_STRVAL_PP(value),1);
|
RETVAL_XML_STRING(Z_STRVAL_PP(value), ZSTR_DUPLICATE);
|
||||||
} else {
|
} else {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} end xsl_xsltprocessor_get_parameter */
|
/* }}} end xsl_xsltprocessor_get_parameter */
|
||||||
|
|
||||||
/* {{{ proto bool xsl_xsltprocessor_remove_parameter(string namespace, string name);
|
/* {{{ proto bool xsl_xsltprocessor_remove_parameter(string namespace, string name); U
|
||||||
*/
|
*/
|
||||||
PHP_FUNCTION(xsl_xsltprocessor_remove_parameter)
|
PHP_FUNCTION(xsl_xsltprocessor_remove_parameter)
|
||||||
{
|
{
|
||||||
|
@ -684,9 +717,10 @@ PHP_FUNCTION(xsl_xsltprocessor_remove_parameter)
|
||||||
|
|
||||||
DOM_GET_THIS(id);
|
DOM_GET_THIS(id);
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &namespace, &namespace_len, &name, &name_len) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&s&", &namespace, &namespace_len, UG(utf8_conv), &name, &name_len, UG(utf8_conv)) == FAILURE) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
||||||
if ( zend_hash_del(intern->parameter, name, name_len + 1) == SUCCESS) {
|
if ( zend_hash_del(intern->parameter, name, name_len + 1) == SUCCESS) {
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
|
@ -708,14 +742,13 @@ PHP_FUNCTION(xsl_xsltprocessor_register_php_functions)
|
||||||
|
|
||||||
DOM_GET_THIS(id);
|
DOM_GET_THIS(id);
|
||||||
|
|
||||||
|
|
||||||
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "a", &array_value) == SUCCESS) {
|
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "a", &array_value) == SUCCESS) {
|
||||||
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
intern = (xsl_object *)zend_object_store_get_object(id TSRMLS_CC);
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value));
|
zend_hash_internal_pointer_reset(Z_ARRVAL_P(array_value));
|
||||||
|
|
||||||
while (zend_hash_get_current_data(Z_ARRVAL_P(array_value), (void **)&entry) == SUCCESS) {
|
while (zend_hash_get_current_data(Z_ARRVAL_P(array_value), (void **)&entry) == SUCCESS) {
|
||||||
SEPARATE_ZVAL(entry);
|
SEPARATE_ZVAL(entry);
|
||||||
convert_to_string_ex(entry);
|
convert_to_string_with_converter(*entry, UG(utf8_conv));
|
||||||
|
|
||||||
MAKE_STD_ZVAL(new_string);
|
MAKE_STD_ZVAL(new_string);
|
||||||
ZVAL_LONG(new_string,1);
|
ZVAL_LONG(new_string,1);
|
||||||
|
@ -742,7 +775,7 @@ PHP_FUNCTION(xsl_xsltprocessor_register_php_functions)
|
||||||
}
|
}
|
||||||
/* }}} end xsl_xsltprocessor_register_php_functions(); */
|
/* }}} end xsl_xsltprocessor_register_php_functions(); */
|
||||||
|
|
||||||
/* {{{ proto bool xsl_xsltprocessor_has_exslt_support();
|
/* {{{ proto bool xsl_xsltprocessor_has_exslt_support(); U
|
||||||
*/
|
*/
|
||||||
PHP_FUNCTION(xsl_xsltprocessor_has_exslt_support)
|
PHP_FUNCTION(xsl_xsltprocessor_has_exslt_support)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue