summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/json.c42
-rw-r--r--ext/json/php_json.h12
-rw-r--r--ext/json/tests/003.phpt5
-rw-r--r--ext/json/tests/004.phpt5
-rw-r--r--ext/json/tests/json_encode_basic.phpt4
5 files changed, 45 insertions, 23 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index c43401868..3e5d23fd9 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: json.c 293036 2010-01-03 09:23:27Z sebastian $ */
+/* $Id: json.c 301028 2010-07-06 17:01:30Z scottmac $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -37,15 +37,6 @@ static PHP_FUNCTION(json_last_error);
static const char digits[] = "0123456789abcdef";
-#define PHP_JSON_HEX_TAG (1<<0)
-#define PHP_JSON_HEX_AMP (1<<1)
-#define PHP_JSON_HEX_APOS (1<<2)
-#define PHP_JSON_HEX_QUOT (1<<3)
-#define PHP_JSON_FORCE_OBJECT (1<<4)
-
-#define PHP_JSON_OUTPUT_ARRAY 0
-#define PHP_JSON_OUTPUT_OBJECT 1
-
ZEND_DECLARE_MODULE_GLOBALS(json)
/* {{{ arginfo */
@@ -81,12 +72,14 @@ static PHP_MINIT_FUNCTION(json)
REGISTER_LONG_CONSTANT("JSON_HEX_APOS", PHP_JSON_HEX_APOS, CONST_CS | CONST_PERSISTENT);
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_ERROR_NONE", PHP_JSON_ERROR_NONE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_ERROR_DEPTH", PHP_JSON_ERROR_DEPTH, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_ERROR_STATE_MISMATCH", PHP_JSON_ERROR_STATE_MISMATCH, CONST_CS | CONST_PERSISTENT);
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);
return SUCCESS;
}
@@ -293,6 +286,30 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
return;
}
+ if (options & PHP_JSON_NUMERIC_CHECK) {
+ double d;
+ int type;
+ long p;
+
+ if ((type = is_numeric_string(s, len, &p, &d, 0)) != 0) {
+ if (type == IS_LONG) {
+ smart_str_append_long(buf, p);
+ } else if (type == IS_DOUBLE) {
+ if (!zend_isinf(d) && !zend_isnan(d)) {
+ char *tmp;
+ int l = spprintf(&tmp, 0, "%.*k", (int) EG(precision), d);
+ smart_str_appendl(buf, tmp, l);
+ efree(tmp);
+ } else {
+ 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');
+ }
+ }
+ return;
+ }
+
+ }
+
utf16 = (unsigned short *) safe_emalloc(len, sizeof(unsigned short), 0);
len = utf8_to_utf16(utf16, s, len);
@@ -444,7 +461,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 {
- zend_error(E_WARNING, "[json] (php_json_encode) double %.9g does not conform to the JSON spec, encoded as 0", dbl);
+ 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');
}
}
@@ -460,7 +477,7 @@ PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_
break;
default:
- zend_error(E_WARNING, "[json] (php_json_encode) type is unsupported, encoded as null");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "type is unsupported, encoded as null");
smart_str_appendl(buf, "null", 4);
break;
}
@@ -483,6 +500,7 @@ PHP_JSON_API void php_json_decode(zval *return_value, char *str, int str_len, ze
if (utf16) {
efree(utf16);
}
+ JSON_G(error_code) = PHP_JSON_ERROR_UTF8;
RETURN_NULL();
}
diff --git a/ext/json/php_json.h b/ext/json/php_json.h
index 44c876f21..37efd9c64 100644
--- a/ext/json/php_json.h
+++ b/ext/json/php_json.h
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_json.h 293036 2010-01-03 09:23:27Z sebastian $ */
+/* $Id: php_json.h 299535 2010-05-20 19:37:52Z iliaa $ */
#ifndef PHP_JSON_H
#define PHP_JSON_H
@@ -50,6 +50,16 @@ ZEND_END_MODULE_GLOBALS(json)
PHP_JSON_API void php_json_encode(smart_str *buf, zval *val, int options TSRMLS_DC);
PHP_JSON_API void php_json_decode(zval *return_value, char *str, int str_len, zend_bool assoc, long depth TSRMLS_DC);
+#define PHP_JSON_HEX_TAG (1<<0)
+#define PHP_JSON_HEX_AMP (1<<1)
+#define PHP_JSON_HEX_APOS (1<<2)
+#define PHP_JSON_HEX_QUOT (1<<3)
+#define PHP_JSON_FORCE_OBJECT (1<<4)
+#define PHP_JSON_NUMERIC_CHECK (1<<5)
+
+#define PHP_JSON_OUTPUT_ARRAY 0
+#define PHP_JSON_OUTPUT_OBJECT 1
+
#endif /* PHP_JSON_H */
/*
diff --git a/ext/json/tests/003.phpt b/ext/json/tests/003.phpt
index f10baa9d1..3b52fb088 100644
--- a/ext/json/tests/003.phpt
+++ b/ext/json/tests/003.phpt
@@ -21,10 +21,7 @@ array(1) {
[0]=>
&array(1) {
[0]=>
- &array(1) {
- [0]=>
- *RECURSION*
- }
+ *RECURSION*
}
}
diff --git a/ext/json/tests/004.phpt b/ext/json/tests/004.phpt
index 884d87420..1d282f9a9 100644
--- a/ext/json/tests/004.phpt
+++ b/ext/json/tests/004.phpt
@@ -16,10 +16,7 @@ echo "Done\n";
--EXPECTF--
object(stdClass)#%d (1) {
["prop"]=>
- object(stdClass)#%d (1) {
- ["prop"]=>
- *RECURSION*
- }
+ *RECURSION*
}
Warning: json_encode(): recursion detected in %s on line %d
diff --git a/ext/json/tests/json_encode_basic.phpt b/ext/json/tests/json_encode_basic.phpt
index 4124d0658..003fcd44c 100644
--- a/ext/json/tests/json_encode_basic.phpt
+++ b/ext/json/tests/json_encode_basic.phpt
@@ -151,8 +151,8 @@ string(4) "null"
string(4) "null"
-- Iteration 26 --
-Warning: [json] (php_json_encode) type is unsupported, encoded as null in %s on line %d
+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=== \ No newline at end of file
+===Done===