Commit:    d372b33c9b941be9a795bf3705bd22dc5f6092c3
Author:    Nikita Popov <ni...@php.net>         Wed, 27 Jun 2012 12:28:55 +0200
Parents:   9a86784859067eaca44cad7f8b4aea00e3ffe6b2 
4662151ea7d7b6920d115cf2a2d6e9d4232727a3
Branches:  PHP-5.4 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=d372b33c9b941be9a795bf3705bd22dc5f6092c3

Log:
Merge branch 'PHP-5.3' into PHP-5.4

* PHP-5.3:
  Improve JSON error handling

Conflicts:
        ext/json/tests/bug54058.phpt
        ext/json/tests/bug61537.phpt

Bugs:
https://bugs.php.net/54058
https://bugs.php.net/61537

Changed paths:
  MM  ext/json/json.c
  MA  ext/json/tests/bug43941.phpt
  MA  ext/json/tests/bug53946.phpt
  MA  ext/json/tests/bug61978.phpt
  MM  main/php_version.h


Diff:
diff --cc ext/json/json.c
index bc30251,5e0351f..5ea3070
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@@ -52,10 -49,10 +52,11 @@@ ZEND_BEGIN_ARG_INFO_EX(arginfo_json_dec
        ZEND_ARG_INFO(0, json)
        ZEND_ARG_INFO(0, assoc)
        ZEND_ARG_INFO(0, depth)
 +      ZEND_ARG_INFO(0, options)
  ZEND_END_ARG_INFO()
  
- ZEND_BEGIN_ARG_INFO(arginfo_json_last_error, 0)
+ ZEND_BEGIN_ARG_INFO_EX(arginfo_json_last_error, 0, 0, 0)
+       ZEND_ARG_INFO(0, as_string)
  ZEND_END_ARG_INFO()
  /* }}} */
  
@@@ -393,9 -323,8 +392,8 @@@ static void json_escape_string(smart_st
                if (utf16) {
                        efree(utf16);
                }
 -              if (len < 0) {
 +              if (ulen < 0) {
                        JSON_G(error_code) = PHP_JSON_ERROR_UTF8;
-                       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);
@@@ -506,57 -428,7 +504,56 @@@
        }
  
        smart_str_appendc(buf, '"');
 -      efree(utf16);
 +      if (utf16) {
 +              efree(utf16);
 +      }
 +}
 +/* }}} */
 +
 +
 +static void json_encode_serializable_object(smart_str *buf, zval *val, int 
options TSRMLS_DC) /* {{{ */
 +{
 +      zend_class_entry *ce = Z_OBJCE_P(val);
 +      zval *retval = NULL, fname;
 +      HashTable* myht;
 +      
 +      if (Z_TYPE_P(val) == IS_ARRAY) {
 +              myht = HASH_OF(val);
 +      } else {
 +              myht = Z_OBJPROP_P(val);
 +      }       
 +      
 +      if (myht && myht->nApplyCount > 1) {
 +              JSON_G(error_code) = PHP_JSON_ERROR_RECURSION;
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion 
detected");
 +              smart_str_appendl(buf, "null", 4);
 +              return;
 +      }
 +
 +      ZVAL_STRING(&fname, "jsonSerialize", 0);
 +
 +      if (FAILURE == call_user_function_ex(EG(function_table), &val, &fname, 
&retval, 0, NULL, 1, NULL TSRMLS_CC) || !retval) {
 +              zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Failed calling 
%s::jsonSerialize()", ce->name);
 +              smart_str_appendl(buf, "null", sizeof("null") - 1);
 +              return;
 +    }   
 +
 +      if (EG(exception)) {
 +              /* Error already raised */
 +              zval_ptr_dtor(&retval);
 +              smart_str_appendl(buf, "null", sizeof("null") - 1);
 +              return;
 +      }
 +
 +      if ((Z_TYPE_P(retval) == IS_OBJECT) &&
 +              (Z_OBJ_HANDLE_P(retval) == Z_OBJ_HANDLE_P(val))) {
 +              /* Handle the case where jsonSerialize does: return $this; by 
going straight to encode array */
 +              json_encode_array(buf, &retval, options TSRMLS_CC);
 +      } else {
 +              /* All other types, encode as normal */
 +              php_json_encode(buf, retval, options TSRMLS_CC);
 +      }
 +
 +      zval_ptr_dtor(&retval);
  }
  /* }}} */
  
diff --cc ext/json/tests/bug43941.phpt
index fb59b71,0000000..48bd7ad
mode 100644,000000..100644
--- a/ext/json/tests/bug43941.phpt
+++ b/ext/json/tests/bug43941.phpt
@@@ -1,28 -1,0 +1,20 @@@
 +--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\xE0", JSON_PARTIAL_OUTPUT_ON_ERROR));
 +var_dump(json_encode(array("ab\xE0", "ab\xE0c", "abc"), 
JSON_PARTIAL_OUTPUT_ON_ERROR));
 +
 +echo "Done\n";
 +?>
 +--EXPECTF--
 +string(5) ""abc""
- 
- Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
 +bool(false)
- 
- Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
 +string(4) "null"
- 
- Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
- 
- Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
 +string(17) "[null,null,"abc"]"
 +Done
diff --cc ext/json/tests/bug53946.phpt
index 079906f,0000000..111438d
mode 100644,000000..100644
--- a/ext/json/tests/bug53946.phpt
+++ b/ext/json/tests/bug53946.phpt
@@@ -1,20 -1,0 +1,16 @@@
 +--TEST--
 +bug #53946 (json_encode() with JSON_UNESCAPED_UNICODE)
 +--SKIPIF--
 +<?php if (!extension_loaded("json")) print "skip"; ?>
 +--FILE--
 +<?php
 +var_dump(json_encode("latin 1234 -/    russian мама мыла раму  specialchars 
\x02   \x08 \n   U+1D11E >𝄞<"));
 +var_dump(json_encode("latin 1234 -/    russian мама мыла раму  specialchars 
\x02   \x08 \n   U+1D11E >𝄞<", JSON_UNESCAPED_UNICODE));
 +var_dump(json_encode("ab\xE0"));
 +var_dump(json_encode("ab\xE0", JSON_UNESCAPED_UNICODE));
 +?>
 +--EXPECTF--
 +string(156) ""latin 1234 -\/    russian \u043c\u0430\u043c\u0430 
\u043c\u044b\u043b\u0430 \u0440\u0430\u043c\u0443  specialchars \u0002   \b \n  
 U+1D11E >\ud834\udd1e<""
 +string(100) ""latin 1234 -\/    russian мама мыла раму  specialchars \u0002   
\b \n   U+1D11E >𝄞<""
- 
- Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
 +bool(false)
- 
- Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
 +bool(false)
diff --cc ext/json/tests/bug61978.phpt
index 4c863c6,0000000..c34b03f
mode 100644,000000..100644
--- a/ext/json/tests/bug61978.phpt
+++ b/ext/json/tests/bug61978.phpt
@@@ -1,47 -1,0 +1,43 @@@
 +--TEST--
 +Bug #61978 (Object recursion not detected for classes that implement 
JsonSerializable)
 +--SKIPIF--
 +<?php if (!extension_loaded("json")) print "skip"; ?>
 +--FILE--
 +<?php
 +
 +class JsonTest1 {
 +    public $test;
 +    public $me;
 +    public function __construct() {
 +        $this->test = '123';
 +        $this->me  = $this;
 +    }
 +}
 +
 +class JsonTest2 implements JsonSerializable {
 +    public $test;
 +    public function __construct() {
 +        $this->test = '123';
 +    }
 +    public function jsonSerialize() {
 +        return array(
 +            'test' => $this->test,
 +            'me'   => $this
 +        );
 +    }
 +}
 +
 +
 +$obj1 = new JsonTest1();
 +var_dump(json_encode($obj1, JSON_PARTIAL_OUTPUT_ON_ERROR));
 +
- echo "\n==\n";
++echo "==\n";
 +
 +$obj2 = new JsonTest2();
 +var_dump(json_encode($obj2, JSON_PARTIAL_OUTPUT_ON_ERROR));
 +
 +?>
 +--EXPECTF--
- Warning: json_encode(): recursion detected in %s on line %d
 +string(44) "{"test":"123","me":{"test":"123","me":null}}"
- 
 +==
- 
- Warning: json_encode(): recursion detected in %s on line %d
 +string(44) "{"test":"123","me":{"test":"123","me":null}}"
diff --cc main/php_version.h
index 6b49f40,2f65dbd..4b7709c
--- a/main/php_version.h
+++ b/main/php_version.h
@@@ -1,8 -1,8 +1,8 @@@
  /* automatically generated by configure */
  /* edit configure.in to change version number */
  #define PHP_MAJOR_VERSION 5
 -#define PHP_MINOR_VERSION 3
 -#define PHP_RELEASE_VERSION 15
 +#define PHP_MINOR_VERSION 4
 +#define PHP_RELEASE_VERSION 5
  #define PHP_EXTRA_VERSION "-dev"
 -#define PHP_VERSION "5.3.15-dev"
 -#define PHP_VERSION_ID 50315
 +#define PHP_VERSION "5.4.5-dev"
- #define PHP_VERSION_ID 50404
++#define PHP_VERSION_ID 50405


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

Reply via email to