From: Omar Kilani Date: Thu, 2 Feb 2006 10:54:32 +0000 (+0000) Subject: Fix encoding of empty strings. X-Git-Tag: RELEASE_1_2~314 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=690859c1fd2377e668a78bd4baef1e78c6949adc;p=php Fix encoding of empty strings. Add empty string value test case. --- diff --git a/ext/json/json.c b/ext/json/json.c index c89147fa5f..d955dd1c2d 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -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; } diff --git a/ext/json/php_json.h b/ext/json/php_json.h index b2b0a9caa3..c7f1f009fe 100644 --- a/ext/json/php_json.h +++ b/ext/json/php_json.h @@ -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 diff --git a/ext/json/tests/pass001.1.phpt b/ext/json/tests/pass001.1.phpt index bb333b285d..d5f0be92c7 100644 --- a/ext/json/tests/pass001.1.phpt +++ b/ext/json/tests/pass001.1.phpt @@ -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-- 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"]=>