dmitry                                   Mon, 14 Dec 2009 13:46:46 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=292131

Log:
Fixed urldecode() and rawurldecode() to accept ASCII-Unicode strings

Changed paths:
    U   php/php-src/trunk/Zend/tests/null_argument_001.phpt
    U   php/php-src/trunk/ext/standard/tests/url/rawurldecode_variation_001.phpt
    U   php/php-src/trunk/ext/standard/tests/url/urldecode_variation_001.phpt
    U   php/php-src/trunk/ext/standard/url.c

Modified: php/php-src/trunk/Zend/tests/null_argument_001.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/null_argument_001.phpt	2009-12-14 13:04:27 UTC (rev 292130)
+++ php/php-src/trunk/Zend/tests/null_argument_001.phpt	2009-12-14 13:46:46 UTC (rev 292131)
@@ -19,18 +19,16 @@
 --EXPECTF--
 string(0) ""
 string(0) ""
+string(0) ""

-Warning: urldecode() expects parameter 1 to be strictly a binary string, Unicode string given in %s on line %d
+Warning: urldecode() expects parameter 1 to be string (Unicode or binary), array given in /home/dmitry/php/php6/Zend/tests/null_argument_001.php on line 6
 NULL
-
-Warning: urldecode() expects parameter 1 to be binary string, array given in %s on line %d
-NULL
 string(1) "1"
 string(0) ""

-Warning: urldecode() expects parameter 1 to be binary string, object given in %s on line %d
+Warning: urldecode() expects parameter 1 to be string (Unicode or binary), object given in /home/dmitry/php/php6/Zend/tests/null_argument_001.php on line 9
 NULL

-Warning: urldecode() expects parameter 1 to be binary string, resource given in %s on line %d
+Warning: urldecode() expects parameter 1 to be string (Unicode or binary), resource given in /home/dmitry/php/php6/Zend/tests/null_argument_001.php on line 12
 NULL
 Done

Modified: php/php-src/trunk/ext/standard/tests/url/rawurldecode_variation_001.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/url/rawurldecode_variation_001.phpt	2009-12-14 13:04:27 UTC (rev 292130)
+++ php/php-src/trunk/ext/standard/tests/url/rawurldecode_variation_001.phpt	2009-12-14 13:46:46 UTC (rev 292131)
@@ -60,6 +60,9 @@
       "",
       '',

+      // non ASCII UNICODE
+      "привет",
+
       // object data
       new stdclass(),

@@ -81,8 +84,8 @@
 ?>
 --EXPECTF--
 *** Testing rawurldecode() : usage variations ***
-Error: 8 - Undefined variable: undefined_var, %s(64)
-Error: 8 - Undefined variable: unset_var, %s(67)
+Error: 8 - Undefined variable: undefined_var, %s(%d)
+Error: 8 - Undefined variable: unset_var, %s(%d)

 Arg value 0
 string(1) "0"
@@ -110,30 +113,30 @@

 Arg value 0.5
 string(3) "0.5"
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - rawurldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - rawurldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - rawurldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - rawurldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - rawurldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - rawurldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - rawurldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - rawurldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - rawurldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - rawurldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL

 Arg value
@@ -155,16 +158,18 @@
 string(0) ""

 Arg value
-Error: 2 - rawurldecode() expects parameter 1 to be strictly a binary string, Unicode string given, %s(74)
-NULL
+string(0) ""

 Arg value
-Error: 2 - rawurldecode() expects parameter 1 to be strictly a binary string, Unicode string given, %s(74)
-NULL
-Error: 4096 - Object of class stdClass could not be converted to string, %s(73)
+string(0) ""

+Arg value привет
+Error: 2 - rawurldecode(): Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received, %s(%d)
+bool(false)
+Error: 4096 - Object of class stdClass could not be converted to string, %s(%d)
+
 Arg value
-Error: 2 - rawurldecode() expects parameter 1 to be binary string, object given, %s(74)
+Error: 2 - rawurldecode() expects parameter 1 to be string (Unicode or binary), object given, %s(%d)
 NULL

 Arg value

Modified: php/php-src/trunk/ext/standard/tests/url/urldecode_variation_001.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/url/urldecode_variation_001.phpt	2009-12-14 13:04:27 UTC (rev 292130)
+++ php/php-src/trunk/ext/standard/tests/url/urldecode_variation_001.phpt	2009-12-14 13:46:46 UTC (rev 292131)
@@ -60,6 +60,9 @@
       "",
       '',

+      // non ASCII UNICODE
+      "привет",
+
       // object data
       new stdclass(),

@@ -81,8 +84,8 @@
 ?>
 --EXPECTF--
 *** Testing urldecode() : usage variations ***
-Error: 8 - Undefined variable: undefined_var, %s(64)
-Error: 8 - Undefined variable: unset_var, %s(67)
+Error: 8 - Undefined variable: undefined_var, %s(%d)
+Error: 8 - Undefined variable: unset_var, %s(%d)

 Arg value 0
 string(1) "0"
@@ -110,30 +113,30 @@

 Arg value 0.5
 string(3) "0.5"
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - urldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - urldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - urldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - urldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - urldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - urldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - urldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - urldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL
-Error: 8 - Array to string conversion, %s(73)
+Error: 8 - Array to string conversion, %s(%d)

 Arg value Array
-Error: 2 - urldecode() expects parameter 1 to be binary string, array given, %s(74)
+Error: 2 - urldecode() expects parameter 1 to be string (Unicode or binary), array given, %s(%d)
 NULL

 Arg value
@@ -155,16 +158,18 @@
 string(0) ""

 Arg value
-Error: 2 - urldecode() expects parameter 1 to be strictly a binary string, Unicode string given, %s(74)
-NULL
+string(0) ""

 Arg value
-Error: 2 - urldecode() expects parameter 1 to be strictly a binary string, Unicode string given, %s(74)
-NULL
-Error: 4096 - Object of class stdClass could not be converted to string, %s(73)
+string(0) ""

+Arg value привет
+Error: 2 - urldecode(): Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received, %s(%d)
+bool(false)
+Error: 4096 - Object of class stdClass could not be converted to string, %s(%d)
+
 Arg value
-Error: 2 - urldecode() expects parameter 1 to be binary string, object given, %s(74)
+Error: 2 - urldecode() expects parameter 1 to be string (Unicode or binary), object given, %s(%d)
 NULL

 Arg value

Modified: php/php-src/trunk/ext/standard/url.c
===================================================================
--- php/php-src/trunk/ext/standard/url.c	2009-12-14 13:04:27 UTC (rev 292130)
+++ php/php-src/trunk/ext/standard/url.c	2009-12-14 13:46:46 UTC (rev 292131)
@@ -622,17 +622,31 @@
    Decodes URL-encoded string */
 PHP_FUNCTION(urldecode)
 {
-	char *in_str, *out_str;
+	zstr in_str;
+	char *out_str;
 	int in_str_len, out_str_len;
+	zend_uchar in_str_type;

-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &in_str,
-							  &in_str_len) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &in_str,
+							  &in_str_len, &in_str_type) == FAILURE) {
 		return;
 	}

-	out_str = estrndup(in_str, in_str_len);
+	if (in_str_type == IS_UNICODE) {
+		in_str.s = zend_unicode_to_ascii(in_str.u, in_str_len TSRMLS_CC);
+		if (!in_str.s) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
+			RETURN_FALSE;
+		}
+	}
+
+	out_str = estrndup(in_str.s, in_str_len);
 	out_str_len = php_url_decode(out_str, in_str_len);

+	if (in_str_type == IS_UNICODE) {
+		efree(in_str.s);
+	}
+
     RETURN_STRINGL(out_str, out_str_len, 0);
 }
 /* }}} */
@@ -744,17 +758,31 @@
    Decodes URL-encodes string */
 PHP_FUNCTION(rawurldecode)
 {
-	char *in_str, *out_str;
+	zstr in_str;
+	char *out_str;
 	int in_str_len, out_str_len;
+	zend_uchar in_str_type;

-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &in_str,
-							  &in_str_len) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t", &in_str,
+							  &in_str_len, &in_str_type) == FAILURE) {
 		return;
 	}

-	out_str = estrndup(in_str, in_str_len);
+	if (in_str_type == IS_UNICODE) {
+		in_str.s = zend_unicode_to_ascii(in_str.u, in_str_len TSRMLS_CC);
+		if (!in_str.s) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Binary or ASCII-Unicode string expected, non-ASCII-Unicode string received");
+			RETURN_FALSE;
+		}
+	}
+
+	out_str = estrndup(in_str.s, in_str_len);
 	out_str_len = php_raw_url_decode(out_str, in_str_len);

+	if (in_str_type == IS_UNICODE) {
+		efree(in_str.s);
+	}
+
     RETURN_STRINGL(out_str, out_str_len, 0);
 }
 /* }}} */
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to