]> granicus.if.org Git - php/commitdiff
Fixed urldecode() and rawurldecode() to accept ASCII-Unicode strings
authorDmitry Stogov <dmitry@php.net>
Mon, 14 Dec 2009 13:46:46 +0000 (13:46 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 14 Dec 2009 13:46:46 +0000 (13:46 +0000)
Zend/tests/null_argument_001.phpt
ext/standard/tests/url/rawurldecode_variation_001.phpt
ext/standard/tests/url/urldecode_variation_001.phpt
ext/standard/url.c

index 2c6682a9af049a642274fa57829f0add4df55164..1c9922612813a2b39f02ad1fd2b3546de4fd3096 100644 (file)
@@ -19,18 +19,16 @@ echo "Done\n";
 --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
-NULL
-
-Warning: urldecode() expects parameter 1 to be binary string, array 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
 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
index 8edc7bc6055a244d2e1079bde5c7a2eb416edc43..8e33d84d503d12ca5a0039705be36f141effaf62 100644 (file)
@@ -60,6 +60,9 @@ $values = array(
       "",
       '',
 
+      // non ASCII UNICODE
+      "привет",
+
       // object data
       new stdclass(),
 
@@ -81,8 +84,8 @@ echo "Done";
 ?>
 --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 @@ string(13) "1.07654321E-9"
 
 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 @@ Arg value
 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  
index 01421d5e407e8f65b2f28d6a379c9a9c94b3028e..2ecb1dcc7da150e1428b9a4079fe57ccc411be0e 100644 (file)
@@ -60,6 +60,9 @@ $values = array(
       "",
       '',
 
+      // non ASCII UNICODE
+      "привет",
+
       // object data
       new stdclass(),
 
@@ -81,8 +84,8 @@ echo "Done";
 ?>
 --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 @@ string(13) "1.07654321E-9"
 
 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 @@ Arg value
 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  
index 52566e9b3c713ddf6b69bba8c704884cf9f8a5cc..9a8d65b4745dea168365fcb050ef32200da2c1cd 100644 (file)
@@ -622,17 +622,31 @@ PHP_FUNCTION(urlencode)
    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 @@ PHP_FUNCTION(rawurlencode)
    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);
 }
 /* }}} */