Hi,

please make sure to merge things upwards. i see the patch was applied to
5.4 and master, too, but git doesn't know about the merge.

johannes

On Mon, 2012-04-02 at 01:46 +0000, Adam Harvey wrote:
> Commit:    3f3ad30c50c32327e723046bcc6649d05dd9236a
> Author:    Adam Harvey <a...@pwd.net.au>         Mon, 2 Apr 2012 09:46:18 
> +0800
> Parents:   1c8fccdf6d6d04d8e6a5dedd7c9d6b1afda8839f
> Branches:  PHP-5.3
> 
> Link:       
> http://git.php.net/?p=php-src.git;a=commitdiff;h=3f3ad30c50c32327e723046bcc6649d05dd9236a
> 
> Log:
> Fix bug #61537 (json_encode() incorrectly truncates/discards information) and
> remove a test case that's now mooted by this fix.
> 
> Bugs:
> https://bugs.php.net/61537
> 
> Changed paths:
>   M  NEWS
>   M  ext/json/json.c
>   M  ext/json/php_json.h
>   D  ext/json/tests/bug43941.phpt
>   M  ext/json/tests/bug54058.phpt
>   A  ext/json/tests/bug61537.phpt
> 
> 
> Diff:
> diff --git a/NEWS b/NEWS
> index a660a91..b9af819 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -2,6 +2,10 @@ PHP                                                          
>               NEWS
>  
> |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
>  ?? ??? 2012, PHP 5.3.12
>  
> +- JSON
> +  . Fixed bug #61537 (json_encode() incorrectly truncates/discards
> +    information). (Adam)
> +
>  ?? ??? 2012, PHP 5.3.11
>  - Iconv extension:
>    . Fixed a bug that iconv extension fails to link to the correct library
> diff --git a/ext/json/json.c b/ext/json/json.c
> index 5b62c2f..ce2cf43 100644
> --- a/ext/json/json.c
> +++ b/ext/json/json.c
> @@ -73,6 +73,7 @@ static PHP_MINIT_FUNCTION(json)
>       REGISTER_LONG_CONSTANT("JSON_HEX_QUOT", PHP_JSON_HEX_QUOT, CONST_CS | 
> CONST_PERSISTENT);
>       REGISTER_LONG_CONSTANT("JSON_FORCE_OBJECT", PHP_JSON_FORCE_OBJECT, 
> CONST_CS | CONST_PERSISTENT);
>       REGISTER_LONG_CONSTANT("JSON_NUMERIC_CHECK", PHP_JSON_NUMERIC_CHECK, 
> CONST_CS | CONST_PERSISTENT);
> +     REGISTER_LONG_CONSTANT("JSON_PARTIAL_OUTPUT_ON_ERROR", 
> PHP_JSON_PARTIAL_OUTPUT_ON_ERROR, CONST_CS | CONST_PERSISTENT);
>  
>       REGISTER_LONG_CONSTANT("JSON_ERROR_NONE", PHP_JSON_ERROR_NONE, CONST_CS 
> | CONST_PERSISTENT);
>       REGISTER_LONG_CONSTANT("JSON_ERROR_DEPTH", PHP_JSON_ERROR_DEPTH, 
> CONST_CS | CONST_PERSISTENT);
> @@ -320,9 +321,7 @@ static void json_escape_string(smart_str *buf, char *s, 
> int len, int options TSR
>               }
>               if (len < 0) {
>                       JSON_G(error_code) = PHP_JSON_ERROR_UTF8;
> -                     if (!PG(display_errors)) {
> -                             php_error_docref(NULL TSRMLS_CC, E_WARNING, 
> "Invalid UTF-8 sequence in argument");
> -                     }
> +                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid 
> UTF-8 sequence in argument");
>                       smart_str_appendl(buf, "null", 4);
>               } else {
>                       smart_str_appendl(buf, "\"\"", 2);
> @@ -571,7 +570,11 @@ static PHP_FUNCTION(json_encode)
>  
>       php_json_encode(&buf, parameter, options TSRMLS_CC);
>  
> -     ZVAL_STRINGL(return_value, buf.c, buf.len, 1);
> +     if (JSON_G(error_code) != PHP_JSON_ERROR_NONE && options ^ 
> PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) {
> +             ZVAL_FALSE(return_value);
> +     } else {
> +             ZVAL_STRINGL(return_value, buf.c, buf.len, 1);
> +     }
>  
>       smart_str_free(&buf);
>  }
> diff --git a/ext/json/php_json.h b/ext/json/php_json.h
> index b104d4c..3cb4902 100644
> --- a/ext/json/php_json.h
> +++ b/ext/json/php_json.h
> @@ -56,6 +56,7 @@ PHP_JSON_API void php_json_decode(zval *return_value, char 
> *str, int str_len, ze
>  #define PHP_JSON_HEX_QUOT    (1<<3)
>  #define PHP_JSON_FORCE_OBJECT        (1<<4)
>  #define PHP_JSON_NUMERIC_CHECK       (1<<5)
> +#define PHP_JSON_PARTIAL_OUTPUT_ON_ERROR     (1<<9)
>  
>  #define PHP_JSON_OUTPUT_ARRAY 0
>  #define PHP_JSON_OUTPUT_OBJECT 1
> diff --git a/ext/json/tests/bug43941.phpt b/ext/json/tests/bug43941.phpt
> deleted file mode 100644
> index 0f86d1d..0000000
> --- a/ext/json/tests/bug43941.phpt
> +++ /dev/null
> @@ -1,21 +0,0 @@
> ---TEST--
> -Bug #43941 (json_encode() invalid UTF-8)
> ---SKIPIF--
> -<?php if (!extension_loaded("json")) print "skip"; ?>
> ---FILE--
> -<?php
> -
> -var_dump(json_encode("abc"));
> -var_dump(json_encode("ab\xE0"));
> -var_dump(json_encode("ab\xE0c"));
> -var_dump(json_encode(array("ab\xE0", "ab\xE0c", "abc")));
> -
> -echo "Done\n";
> -?>
> ---EXPECTF--
> -string(5) ""abc""
> -string(4) "null"
> -string(4) "null"
> -string(17) "[null,null,"abc"]"
> -Done
> -
> diff --git a/ext/json/tests/bug54058.phpt b/ext/json/tests/bug54058.phpt
> index 3b1136b..08c7f57 100644
> --- a/ext/json/tests/bug54058.phpt
> +++ b/ext/json/tests/bug54058.phpt
> @@ -29,7 +29,14 @@ json_encode($c);
>  var_dump(json_last_error());
>  ?>
>  --EXPECTF--
> +Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
>  int(5)
> +
> +Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
>  int(5)
> +
> +Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
>  int(5)
> +
> +Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
>  int(5)
> diff --git a/ext/json/tests/bug61537.phpt b/ext/json/tests/bug61537.phpt
> new file mode 100644
> index 0000000..e2abdda
> --- /dev/null
> +++ b/ext/json/tests/bug61537.phpt
> @@ -0,0 +1,30 @@
> +--TEST--
> +Bug #61537 (json_encode() incorrectly truncates/discards information)
> +--SKIPIF--
> +<?php if (!extension_loaded("json")) print "skip"; ?>
> +--FILE--
> +<?php
> +$invalid_utf8 = "\x9f";
> +var_dump(json_encode($invalid_utf8), json_last_error());
> +var_dump(json_encode($invalid_utf8, JSON_PARTIAL_OUTPUT_ON_ERROR), 
> json_last_error());
> +
> +$invalid_utf8 = "an invalid sequen\xce in the middle of a string";
> +var_dump(json_encode($invalid_utf8), json_last_error());
> +var_dump(json_encode($invalid_utf8, JSON_PARTIAL_OUTPUT_ON_ERROR), 
> json_last_error());
> +?>
> +--EXPECTF--
> +Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
> +bool(false)
> +int(5)
> +
> +Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
> +string(4) "null"
> +int(5)
> +
> +Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
> +bool(false)
> +int(5)
> +
> +Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
> +string(4) "null"
> +int(5)
> 
> 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to