]> granicus.if.org Git - php/commitdiff
Fix encoding of empty strings.
authorOmar Kilani <omar@php.net>
Thu, 2 Feb 2006 10:54:32 +0000 (10:54 +0000)
committerOmar Kilani <omar@php.net>
Thu, 2 Feb 2006 10:54:32 +0000 (10:54 +0000)
Add empty string value test case.

ext/json/json.c
ext/json/php_json.h
ext/json/tests/pass001.1.phpt

index c89147fa5ff09d6003cc773d84591dc6e62f9ec3..d955dd1c2d8f80983ce03f452af9905b24eb677a 100644 (file)
@@ -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;
     }
 
index b2b0a9caa3df8ae9da9f04b9c10bc179e833bcea..c7f1f009fe852d43864bd1fc2b147a0e5ffad416 100644 (file)
@@ -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
index bb333b285d68b950879eb19e4192d03ab7ed200b..d5f0be92c7a165093f9d6db97012c3bb435564d3 100644 (file)
@@ -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":"&#34; \" %22 0x22 034 &#x22;","\/\\\"\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":"&#34; \" %22 0x22 034 &#x22;","\/\\\"\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":"&#34; \" %22 0x22 034 &#x22;","\/\\\"\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":"&#34; \" %22 0x22 034 &#x22;","\/\\\"\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"]=>