mirror of
https://github.com/php/php-src.git
synced 2025-01-26 21:54:16 +08:00
Fix encoding of empty strings.
Add empty string value test case.
This commit is contained in:
parent
ed3a54c657
commit
690859c1fd
@ -208,6 +208,12 @@ static void json_escape_string(smart_str *buf, char *s, int len TSRMLS_DC)
|
||||
unsigned short us;
|
||||
unsigned short *utf16;
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
smart_str_appendl(buf, "\"\"", 2);
|
||||
return;
|
||||
}
|
||||
|
||||
utf16 = (unsigned short *) emalloc(len * sizeof(unsigned short));
|
||||
|
||||
len = utf8_to_utf16(utf16, s, len);
|
||||
@ -218,6 +224,7 @@ static void json_escape_string(smart_str *buf, char *s, int len TSRMLS_DC)
|
||||
efree(utf16);
|
||||
}
|
||||
|
||||
smart_str_appendl(buf, "\"\"", 2);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#ifndef PHP_JSON_H
|
||||
#define PHP_JSON_H
|
||||
|
||||
#define PHP_JSON_VERSION "1.2.0-BETA"
|
||||
#define PHP_JSON_VERSION "1.2.0-BETA2"
|
||||
|
||||
extern zend_module_entry json_module_entry;
|
||||
#define phpext_json_ptr &json_module_entry
|
||||
|
@ -2,6 +2,7 @@
|
||||
JSON Test Pattern pass1.1
|
||||
Modified to test unescaped UNICODE as keys and values.
|
||||
Modified to test numbers with exponents without a decimal point.
|
||||
Modified to test empty string values.
|
||||
http://www.crockford.com/JSON/JSON_checker/test/pass1.json
|
||||
--SKIPIF--
|
||||
<?php
|
||||
@ -43,6 +44,7 @@ $test = "
|
||||
\"hex\": \"\\u0123\\u4567\\u89AB\\uCDEF\\uabcd\\uef4A\",
|
||||
\"unicode\": \"\\u30d7\\u30ec\\u30b9\\u30ad\\u30c3\\u30c8\",
|
||||
\"プレスキット\": \"プレスキット\",
|
||||
\"empty_string\": \"\",
|
||||
\"true\": true,
|
||||
\"false\": false,
|
||||
\"null\": null,
|
||||
@ -129,6 +131,7 @@ Testing:
|
||||
"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
|
||||
"unicode": "\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8",
|
||||
"プレスキット": "プレスキット",
|
||||
"empty_string": "",
|
||||
"true": true,
|
||||
"false": false,
|
||||
"null": null,
|
||||
@ -186,7 +189,7 @@ array(14) {
|
||||
[7]=>
|
||||
NULL
|
||||
[8]=>
|
||||
object(stdClass)#3 (34) {
|
||||
object(stdClass)#3 (35) {
|
||||
["integer"]=>
|
||||
int(1234567890)
|
||||
["real"]=>
|
||||
@ -229,6 +232,8 @@ array(14) {
|
||||
string(18) "プレスキット"
|
||||
["プレスキット"]=>
|
||||
string(18) "プレスキット"
|
||||
["empty_string"]=>
|
||||
string(0) ""
|
||||
["true"]=>
|
||||
bool(true)
|
||||
["false"]=>
|
||||
@ -330,7 +335,7 @@ array(14) {
|
||||
[7]=>
|
||||
NULL
|
||||
[8]=>
|
||||
array(34) {
|
||||
array(35) {
|
||||
["integer"]=>
|
||||
int(1234567890)
|
||||
["real"]=>
|
||||
@ -373,6 +378,8 @@ array(14) {
|
||||
string(18) "プレスキット"
|
||||
["プレスキット"]=>
|
||||
string(18) "プレスキット"
|
||||
["empty_string"]=>
|
||||
string(0) ""
|
||||
["true"]=>
|
||||
bool(true)
|
||||
["false"]=>
|
||||
@ -448,9 +455,9 @@ array(14) {
|
||||
string(7) "rosebud"
|
||||
}
|
||||
ENCODE: FROM OBJECT
|
||||
["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"_empty_":0,"E no .":4.0e+12,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","unicode":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","true":true,"false":false,"null":null,"array":[],"object":{},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* <!-- --","# -- --> *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"]
|
||||
["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},{},[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"_empty_":0,"E no .":4.0e+12,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","unicode":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","empty_string":"","true":true,"false":false,"null":null,"array":[],"object":{},"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* <!-- --","# -- --> *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"]
|
||||
ENCODE: FROM ARRAY
|
||||
["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},[],[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"_empty_":0,"E no .":4.0e+12,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","unicode":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","true":true,"false":false,"null":null,"array":[],"object":[],"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* <!-- --","# -- --> *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"]
|
||||
["JSON Test Pattern pass1",{"object with 1 member":["array with 1 element"]},[],[],-42,true,false,null,{"integer":1234567890,"real":-9876.54321,"e":1.23456789e-13,"E":1.23456789e+34,"_empty_":0,"E no .":4.0e+12,"zero":0,"one":1,"space":" ","quote":"\"","backslash":"\\","controls":"\b\f\n\r\t","slash":"\/ & \/","alpha":"abcdefghijklmnopqrstuvwyz","ALPHA":"ABCDEFGHIJKLMNOPQRSTUVWYZ","digit":"0123456789","special":"`1~!@#$%^&*()_+-={':[,]}|;.<\/>?","hex":"\u0123\u4567\u89ab\ucdef\uabcd\uef4a","unicode":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8":"\u30d7\u30ec\u30b9\u30ad\u30c3\u30c8","empty_string":"","true":true,"false":false,"null":null,"array":[],"object":[],"address":"50 St. James Street","url":"http:\/\/www.JSON.org\/","comment":"\/\/ \/* <!-- --","# -- --> *\/":" "," s p a c e d ":[1,2,3,4,5,6,7],"compact":[1,2,3,4,5,6,7],"jsontext":"{\"object with 1 member\":[\"array with 1 element\"]}","quotes":"" \" %22 0x22 034 "","\/\\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',.\/<>?":"A key can be any string"},0.5,98.6,99.44,1066,"rosebud"]
|
||||
DECODE AGAIN: AS OBJECT
|
||||
array(14) {
|
||||
[0]=>
|
||||
@ -478,7 +485,7 @@ array(14) {
|
||||
[7]=>
|
||||
NULL
|
||||
[8]=>
|
||||
object(stdClass)#7 (34) {
|
||||
object(stdClass)#7 (35) {
|
||||
["integer"]=>
|
||||
int(1234567890)
|
||||
["real"]=>
|
||||
@ -521,6 +528,8 @@ array(14) {
|
||||
string(18) "プレスキット"
|
||||
["プレスキット"]=>
|
||||
string(18) "プレスキット"
|
||||
["empty_string"]=>
|
||||
string(0) ""
|
||||
["true"]=>
|
||||
bool(true)
|
||||
["false"]=>
|
||||
@ -622,7 +631,7 @@ array(14) {
|
||||
[7]=>
|
||||
NULL
|
||||
[8]=>
|
||||
array(34) {
|
||||
array(35) {
|
||||
["integer"]=>
|
||||
int(1234567890)
|
||||
["real"]=>
|
||||
@ -665,6 +674,8 @@ array(14) {
|
||||
string(18) "プレスキット"
|
||||
["プレスキット"]=>
|
||||
string(18) "プレスキット"
|
||||
["empty_string"]=>
|
||||
string(0) ""
|
||||
["true"]=>
|
||||
bool(true)
|
||||
["false"]=>
|
||||
|
Loading…
Reference in New Issue
Block a user