]> granicus.if.org Git - php/commitdiff
Fix PECL bug #7147 - rework comma insertion whilst encoding.
authorOmar Kilani <omar@php.net>
Sat, 18 Mar 2006 04:15:16 +0000 (04:15 +0000)
committerOmar Kilani <omar@php.net>
Sat, 18 Mar 2006 04:15:16 +0000 (04:15 +0000)
Add tests to package.xml.

ext/json/json.c
ext/json/package.xml
ext/json/php_json.h

index b4f993b239616bf7744273446ce96b2749a8ed21..d19eb2e9b5c4b20eef2558ef966de5f94d59b09e 100644 (file)
@@ -153,8 +153,7 @@ static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) {
         ulong index;
         uint key_len;
         HashPosition pos;
-        int htlen = i;
-        int wpos = 0;
+        int need_comma = 0;
 
         zend_hash_internal_pointer_reset_ex(myht, &pos);
         for (;; zend_hash_move_forward_ex(myht, &pos)) {
@@ -164,6 +163,12 @@ static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) {
 
             if (zend_hash_get_current_data_ex(myht, (void **) &data, &pos) == SUCCESS) {
                 if (r == 0) {
+                    if (need_comma) {
+                        smart_str_appendc(buf, ',');
+                    } else {
+                        need_comma = 1;
+                    }
                     json_encode_r(buf, *data TSRMLS_CC);
                 } else if (r == 1) {
                     if (i == HASH_KEY_IS_STRING) {
@@ -172,11 +177,23 @@ static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) {
                             continue;
                         }
 
+                        if (need_comma) {
+                            smart_str_appendc(buf, ',');
+                        } else {
+                            need_comma = 1;
+                        }
+
                         json_escape_string(buf, key, key_len - 1 TSRMLS_CC);
                         smart_str_appendc(buf, ':');
 
                         json_encode_r(buf, *data TSRMLS_CC);
                     } else {
+                        if (need_comma) {
+                            smart_str_appendc(buf, ',');
+                        } else {
+                            need_comma = 1;
+                        }
+                        
                         smart_str_appendc(buf, '"');
                         smart_str_append_long(buf, (long) index);
                         smart_str_appendc(buf, '"');
@@ -185,11 +202,6 @@ static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) {
                         json_encode_r(buf, *data TSRMLS_CC);
                     }
                 }
-
-                if (htlen > 1 && wpos++ < htlen - 1)
-                {
-                    smart_str_appendc(buf, ',');
-                }
             }
         }
     }
index 3ffeab7bae925c615a0cdf12bf26070a3c0a3222..0651de736fc1b1e9ab55e8864f9e0f5daf1df564 100644 (file)
  <license>PHP 3.01</license>
  <release>
   <state>stable</state>
-  <version>1.2.0</version>
-  <date>2006-03-15</date>
+  <version>1.2.1</version>
+  <date>2006-03-18</date>
   <notes>
-   Complete rewrite using JSON_checker as the base for the parser. Implements the JSON specification. 3-8x faster on encodes and 1.2x-4x faster on decodes.
+   Fix PECL bug #7147 - rework handling of comma insertion while encoding.
+   Add tests to package.xml
   </notes>
  </release>
   <configureoptions>
     <file role="src" name="utf8_decode.h" />
     <file role="src" name="utf8_to_utf16.c" />
     <file role="src" name="utf8_to_utf16.h" />
+    <dir role="test" name="tests">
+      <file role="test" name="fail001.phpt" />
+      <file role="test" name="pass001.phpt" />
+      <file role="test" name="pass001.1.phpt" />
+      <file role="test" name="pass002.phpt" />
+      <file role="test" name="pass003.phpt" />
+    </dir>
   </filelist>
   <changelog>
      <release>
    Cleanup and TSRM performance fixes by rasmus.
   </notes>
  </release>
+ <release>
+  <state>stable</state>
+  <version>1.2.0</version>
+  <date>2006-03-15</date>
+  <notes>
+   Complete rewrite using JSON_checker as the base for the parser. Implements the JSON specification. 3-8x faster on encodes and 1.2x-4x faster on decodes.
+  </notes>
+ </release>
  </changelog>
 </package>
 <!--
index da1b8fe71c7450fb00ad23e0b57c803b65a71b40..48555ee31f2bdfbfbea1c5ddffe3914d14794a62 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef PHP_JSON_H
 #define PHP_JSON_H
 
-#define PHP_JSON_VERSION "1.2.0"
+#define PHP_JSON_VERSION "1.2.1"
 
 extern zend_module_entry json_module_entry;
 #define phpext_json_ptr &json_module_entry