summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2012-07-01 16:28:57 +0200
committerNikita Popov <nikic@php.net>2012-07-01 16:28:57 +0200
commit250393f92523fffe643df06a1de2101fd50a327e (patch)
tree45055777abbb7760270d7652ae0eb01099b4f858
parent5f31c81f0754ac031c2c5c056cb48ff4153fea81 (diff)
downloadphp-git-250393f92523fffe643df06a1de2101fd50a327e.tar.gz
Revert JSON changes to PHP 5.3
This reverts the following commits: 974324676b2436f159f42d9241c569f813471684 4662151ea7d7b6920d115cf2a2d6e9d4232727a3 84fe2cc890e49f40bac7c3ba74b3cfc6dc4cef2f This does not revert the JSON changes released in PHP 5.3.14.
-rw-r--r--ext/json/JSON_parser.h5
-rw-r--r--ext/json/json.c55
-rw-r--r--ext/json/tests/003.phpt17
-rw-r--r--ext/json/tests/004.phpt16
-rw-r--r--ext/json/tests/007.phpt16
-rw-r--r--ext/json/tests/bug54058.phpt20
-rw-r--r--ext/json/tests/bug61537.phpt29
-rw-r--r--ext/json/tests/inf_nan_error.phpt45
-rw-r--r--ext/json/tests/json_encode_basic.phpt4
-rw-r--r--ext/json/tests/pass001.1.phpt4
-rw-r--r--ext/json/tests/pass001.phpt4
-rw-r--r--ext/json/tests/unsupported_type_error.phpt26
12 files changed, 46 insertions, 195 deletions
diff --git a/ext/json/JSON_parser.h b/ext/json/JSON_parser.h
index 5037344890..746190bb35 100644
--- a/ext/json/JSON_parser.h
+++ b/ext/json/JSON_parser.h
@@ -24,10 +24,7 @@ enum error_codes {
PHP_JSON_ERROR_STATE_MISMATCH,
PHP_JSON_ERROR_CTRL_CHAR,
PHP_JSON_ERROR_SYNTAX,
- PHP_JSON_ERROR_UTF8,
- PHP_JSON_ERROR_RECURSION,
- PHP_JSON_ERROR_INF_OR_NAN,
- PHP_JSON_ERROR_UNSUPPORTED_TYPE
+ PHP_JSON_ERROR_UTF8
};
extern JSON_parser new_JSON_parser(int depth);
diff --git a/ext/json/json.c b/ext/json/json.c
index 4d29a66688..ce2cf43fcc 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -34,7 +34,6 @@ static PHP_MINFO_FUNCTION(json);
static PHP_FUNCTION(json_encode);
static PHP_FUNCTION(json_decode);
static PHP_FUNCTION(json_last_error);
-static PHP_FUNCTION(json_last_error_msg);
static const char digits[] = "0123456789abcdef";
@@ -54,9 +53,6 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_json_last_error, 0)
ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO(arginfo_json_last_error_msg, 0)
-ZEND_END_ARG_INFO()
/* }}} */
/* {{{ json_functions[] */
@@ -64,7 +60,6 @@ static const function_entry json_functions[] = {
PHP_FE(json_encode, arginfo_json_encode)
PHP_FE(json_decode, arginfo_json_decode)
PHP_FE(json_last_error, arginfo_json_last_error)
- PHP_FE(json_last_error_msg, arginfo_json_last_error_msg)
PHP_FE_END
};
/* }}} */
@@ -86,9 +81,6 @@ static PHP_MINIT_FUNCTION(json)
REGISTER_LONG_CONSTANT("JSON_ERROR_CTRL_CHAR", PHP_JSON_ERROR_CTRL_CHAR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_ERROR_SYNTAX", PHP_JSON_ERROR_SYNTAX, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_ERROR_UTF8", PHP_JSON_ERROR_UTF8, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("JSON_ERROR_RECURSION", PHP_JSON_ERROR_RECURSION, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("JSON_ERROR_INF_OR_NAN", PHP_JSON_ERROR_INF_OR_NAN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("JSON_ERROR_UNSUPPORTED_TYPE", PHP_JSON_ERROR_UNSUPPORTED_TYPE, CONST_CS | CONST_PERSISTENT);
return SUCCESS;
}
@@ -189,7 +181,7 @@ static void json_encode_array(smart_str *buf, zval **val, int options TSRMLS_DC)
}
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;
}
@@ -311,7 +303,7 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
smart_str_appendl(buf, tmp, l);
efree(tmp);
} else {
- JSON_G(error_code) = PHP_JSON_ERROR_INF_OR_NAN;
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "double %.9g does not conform to the JSON spec, encoded as 0", d);
smart_str_appendc(buf, '0');
}
}
@@ -329,6 +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;
+ 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);
@@ -467,7 +460,7 @@ PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_
smart_str_appendl(buf, d, len);
efree(d);
} else {
- JSON_G(error_code) = PHP_JSON_ERROR_INF_OR_NAN;
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "double %.9g does not conform to the JSON spec, encoded as 0", dbl);
smart_str_appendc(buf, '0');
}
}
@@ -483,7 +476,7 @@ PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_
break;
default:
- JSON_G(error_code) = PHP_JSON_ERROR_UNSUPPORTED_TYPE;
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "type is unsupported, encoded as null");
smart_str_appendl(buf, "null", 4);
break;
}
@@ -577,7 +570,7 @@ static PHP_FUNCTION(json_encode)
php_json_encode(&buf, parameter, options TSRMLS_CC);
- if (JSON_G(error_code) != PHP_JSON_ERROR_NONE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) {
+ 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);
@@ -611,7 +604,7 @@ static PHP_FUNCTION(json_decode)
/* }}} */
/* {{{ proto int json_last_error()
- Returns the error code of the last json_encode() or json_decode() call. */
+ Returns the error code of the last json_decode(). */
static PHP_FUNCTION(json_last_error)
{
if (zend_parse_parameters_none() == FAILURE) {
@@ -622,40 +615,6 @@ static PHP_FUNCTION(json_last_error)
}
/* }}} */
-/* {{{ proto string json_last_error_msg()
- Returns the error string of the last json_encode() or json_decode() call. */
-static PHP_FUNCTION(json_last_error_msg)
-{
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
-
- switch(JSON_G(error_code)) {
- case PHP_JSON_ERROR_NONE:
- RETURN_STRING("No error", 1);
- case PHP_JSON_ERROR_DEPTH:
- RETURN_STRING("Maximum stack depth exceeded", 1);
- case PHP_JSON_ERROR_STATE_MISMATCH:
- RETURN_STRING("State mismatch (invalid or malformed JSON)", 1);
- case PHP_JSON_ERROR_CTRL_CHAR:
- RETURN_STRING("Control character error, possibly incorrectly encoded", 1);
- case PHP_JSON_ERROR_SYNTAX:
- RETURN_STRING("Syntax error", 1);
- case PHP_JSON_ERROR_UTF8:
- RETURN_STRING("Malformed UTF-8 characters, possibly incorrectly encoded", 1);
- case PHP_JSON_ERROR_RECURSION:
- RETURN_STRING("Recursion detected", 1);
- case PHP_JSON_ERROR_INF_OR_NAN:
- RETURN_STRING("Inf and NaN cannot be JSON encoded", 1);
- case PHP_JSON_ERROR_UNSUPPORTED_TYPE:
- RETURN_STRING("Type is not supported", 1);
- default:
- RETURN_STRING("Unknown error", 1);
- }
-
-}
-/* }}} */
-
/*
* Local variables:
* tab-width: 4
diff --git a/ext/json/tests/003.phpt b/ext/json/tests/003.phpt
index 4ce5b0fde9..3b52fb0884 100644
--- a/ext/json/tests/003.phpt
+++ b/ext/json/tests/003.phpt
@@ -9,16 +9,10 @@ $a = array();
$a[] = &$a;
var_dump($a);
-
-echo "\n";
-
var_dump(json_encode($a));
-var_dump(json_last_error(), json_last_error_msg());
-echo "\n";
-
-var_dump(json_encode($a, JSON_PARTIAL_OUTPUT_ON_ERROR));
-var_dump(json_last_error(), json_last_error_msg());
+/* Break circular data structure to prevent memory leaks */
+unset($a[0]);
echo "Done\n";
?>
@@ -31,11 +25,6 @@ array(1) {
}
}
-bool(false)
-int(6)
-string(%d) "Recursion detected"
-
+Warning: json_encode(): recursion detected in %s on line %d
string(8) "[[null]]"
-int(6)
-string(%d) "Recursion detected"
Done
diff --git a/ext/json/tests/004.phpt b/ext/json/tests/004.phpt
index 70ef3ffd1b..1d282f9a96 100644
--- a/ext/json/tests/004.phpt
+++ b/ext/json/tests/004.phpt
@@ -9,16 +9,7 @@ $a = new stdclass;
$a->prop = $a;
var_dump($a);
-
-echo "\n";
-
var_dump(json_encode($a));
-var_dump(json_last_error(), json_last_error_msg());
-
-echo "\n";
-
-var_dump(json_encode($a, JSON_PARTIAL_OUTPUT_ON_ERROR));
-var_dump(json_last_error(), json_last_error_msg());
echo "Done\n";
?>
@@ -28,11 +19,6 @@ object(stdClass)#%d (1) {
*RECURSION*
}
-bool(false)
-int(6)
-string(%d) "Recursion detected"
-
+Warning: json_encode(): recursion detected in %s on line %d
string(22) "{"prop":{"prop":null}}"
-int(6)
-string(%d) "Recursion detected"
Done
diff --git a/ext/json/tests/007.phpt b/ext/json/tests/007.phpt
index 7557ac9ed7..9ee190a24c 100644
--- a/ext/json/tests/007.phpt
+++ b/ext/json/tests/007.phpt
@@ -5,15 +5,15 @@ json_last_error() tests
--FILE--
<?php
var_dump(json_decode("[1]"));
-var_dump(json_last_error(), json_last_error_msg());
+var_dump(json_last_error());
var_dump(json_decode("[[1]]", false, 2));
-var_dump(json_last_error(), json_last_error_msg());
+var_dump(json_last_error());
var_dump(json_decode("[1}"));
-var_dump(json_last_error(), json_last_error_msg());
+var_dump(json_last_error());
var_dump(json_decode('["' . chr(0) . 'abcd"]'));
-var_dump(json_last_error(), json_last_error_msg());
+var_dump(json_last_error());
var_dump(json_decode("[1"));
-var_dump(json_last_error(), json_last_error_msg());
+var_dump(json_last_error());
echo "Done\n";
@@ -24,17 +24,13 @@ array(1) {
int(1)
}
int(0)
-string(8) "No error"
NULL
int(1)
-string(28) "Maximum stack depth exceeded"
NULL
int(2)
-string(42) "State mismatch (invalid or malformed JSON)"
NULL
int(3)
-string(53) "Control character error, possibly incorrectly encoded"
NULL
int(4)
-string(12) "Syntax error"
Done
+
diff --git a/ext/json/tests/bug54058.phpt b/ext/json/tests/bug54058.phpt
index df1b3130f8..08c7f579ab 100644
--- a/ext/json/tests/bug54058.phpt
+++ b/ext/json/tests/bug54058.phpt
@@ -8,33 +8,35 @@ Bug #54058 (json_last_error() invalid UTF-8 produces wrong error)
$bad_utf8 = quoted_printable_decode('=B0');
json_encode($bad_utf8);
-var_dump(json_last_error(), json_last_error_msg());
+var_dump(json_last_error());
$a = new stdclass;
$a->foo = quoted_printable_decode('=B0');
json_encode($a);
-var_dump(json_last_error(), json_last_error_msg());
+var_dump(json_last_error());
$b = new stdclass;
$b->foo = $bad_utf8;
$b->bar = 1;
json_encode($b);
-var_dump(json_last_error(), json_last_error_msg());
+var_dump(json_last_error());
$c = array(
'foo' => $bad_utf8,
'bar' => 1
);
json_encode($c);
-var_dump(json_last_error(), json_last_error_msg());
-
+var_dump(json_last_error());
?>
--EXPECTF--
+Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
int(5)
-string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
+
+Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
int(5)
-string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
+
+Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
int(5)
-string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
+
+Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
int(5)
-string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
diff --git a/ext/json/tests/bug61537.phpt b/ext/json/tests/bug61537.phpt
index 80ed051c9a..e2abdda66a 100644
--- a/ext/json/tests/bug61537.phpt
+++ b/ext/json/tests/bug61537.phpt
@@ -5,35 +5,26 @@ Bug #61537 (json_encode() incorrectly truncates/discards information)
--FILE--
<?php
$invalid_utf8 = "\x9f";
-
-var_dump(json_encode($invalid_utf8));
-var_dump(json_last_error(), json_last_error_msg());
-
-var_dump(json_encode($invalid_utf8, JSON_PARTIAL_OUTPUT_ON_ERROR));
-var_dump(json_last_error(), json_last_error_msg());
-
-echo "\n";
+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));
-var_dump(json_last_error(), json_last_error_msg());
-
-var_dump(json_encode($invalid_utf8, JSON_PARTIAL_OUTPUT_ON_ERROR));
-var_dump(json_last_error(), json_last_error_msg());
-
+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)
-string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
+
+Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
string(4) "null"
int(5)
-string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
+Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
bool(false)
int(5)
-string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
+
+Warning: json_encode(): Invalid UTF-8 sequence in argument in %s on line %d
string(4) "null"
int(5)
-string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
diff --git a/ext/json/tests/inf_nan_error.phpt b/ext/json/tests/inf_nan_error.phpt
deleted file mode 100644
index f9deecc469..0000000000
--- a/ext/json/tests/inf_nan_error.phpt
+++ /dev/null
@@ -1,45 +0,0 @@
---TEST--
-An error is thrown when INF or NaN are encoded
---SKIPIF--
-<?php if (!extension_loaded("json")) print "skip"; ?>
---FILE--
-<?php
-
-$inf = INF;
-
-var_dump($inf);
-
-var_dump(json_encode($inf));
-var_dump(json_last_error(), json_last_error_msg());
-
-var_dump(json_encode($inf, JSON_PARTIAL_OUTPUT_ON_ERROR));
-var_dump(json_last_error(), json_last_error_msg());
-
-echo "\n";
-
-$nan = NAN;
-
-var_dump($nan);
-
-var_dump(json_encode($nan));
-var_dump(json_last_error(), json_last_error_msg());
-
-var_dump(json_encode($nan, JSON_PARTIAL_OUTPUT_ON_ERROR));
-var_dump(json_last_error(), json_last_error_msg());
-?>
---EXPECTF--
-float(INF)
-bool(false)
-int(7)
-string(34) "Inf and NaN cannot be JSON encoded"
-string(1) "0"
-int(7)
-string(34) "Inf and NaN cannot be JSON encoded"
-
-float(NAN)
-bool(false)
-int(7)
-string(34) "Inf and NaN cannot be JSON encoded"
-string(1) "0"
-int(7)
-string(34) "Inf and NaN cannot be JSON encoded"
diff --git a/ext/json/tests/json_encode_basic.phpt b/ext/json/tests/json_encode_basic.phpt
index fc348eed81..003fcd44c6 100644
--- a/ext/json/tests/json_encode_basic.phpt
+++ b/ext/json/tests/json_encode_basic.phpt
@@ -150,7 +150,9 @@ string(4) "null"
-- Iteration 25 --
string(4) "null"
-- Iteration 26 --
-bool(false)
+
+Warning: json_encode(): type is unsupported, encoded as null in %s on line %d
+string(4) "null"
-- Iteration 27 --
string(82) "{"MyInt":99,"MyFloat":123.45,"MyBool":true,"MyNull":null,"MyString":"Hello World"}"
===Done===
diff --git a/ext/json/tests/pass001.1.phpt b/ext/json/tests/pass001.1.phpt
index a51f885780..7e15a7622a 100644
--- a/ext/json/tests/pass001.1.phpt
+++ b/ext/json/tests/pass001.1.phpt
@@ -90,10 +90,10 @@ $arr = json_decode($test, true);
var_dump($arr);
echo "ENCODE: FROM OBJECT\n";
-$obj_enc = json_encode($obj, JSON_PARTIAL_OUTPUT_ON_ERROR);
+$obj_enc = json_encode($obj);
echo $obj_enc . "\n";
echo "ENCODE: FROM ARRAY\n";
-$arr_enc = json_encode($arr, JSON_PARTIAL_OUTPUT_ON_ERROR);
+$arr_enc = json_encode($arr);
echo $arr_enc . "\n";
echo "DECODE AGAIN: AS OBJECT\n";
diff --git a/ext/json/tests/pass001.phpt b/ext/json/tests/pass001.phpt
index 1fd05fcdd8..43be11e2b0 100644
--- a/ext/json/tests/pass001.phpt
+++ b/ext/json/tests/pass001.phpt
@@ -79,10 +79,10 @@ $arr = json_decode($test, true);
var_dump($arr);
echo "ENCODE: FROM OBJECT\n";
-$obj_enc = json_encode($obj, JSON_PARTIAL_OUTPUT_ON_ERROR);
+$obj_enc = json_encode($obj);
echo $obj_enc . "\n";
echo "ENCODE: FROM ARRAY\n";
-$arr_enc = json_encode($arr, JSON_PARTIAL_OUTPUT_ON_ERROR);
+$arr_enc = json_encode($arr);
echo $arr_enc . "\n";
echo "DECODE AGAIN: AS OBJECT\n";
diff --git a/ext/json/tests/unsupported_type_error.phpt b/ext/json/tests/unsupported_type_error.phpt
deleted file mode 100644
index 45a167a5ac..0000000000
--- a/ext/json/tests/unsupported_type_error.phpt
+++ /dev/null
@@ -1,26 +0,0 @@
---TEST--
-An error is thrown when an unsupported type is encoded
---SKIPIF--
-<?php if (!extension_loaded("json")) print "skip"; ?>
---FILE--
-<?php
-
-$resource = fopen(__FILE__, "r");
-
-var_dump($resource);
-
-var_dump(json_encode($resource));
-var_dump(json_last_error(), json_last_error_msg());
-
-var_dump(json_encode($resource, JSON_PARTIAL_OUTPUT_ON_ERROR));
-var_dump(json_last_error(), json_last_error_msg());
-
-?>
---EXPECTF--
-resource(5) of type (stream)
-bool(false)
-int(8)
-string(21) "Type is not supported"
-string(4) "null"
-int(8)
-string(21) "Type is not supported"