Browse Source

Fix PECL bug #7147 - rework comma insertion whilst encoding.

Add tests to package.xml.
migration/RELEASE_1_0_0
Omar Kilani 21 years ago
parent
commit
aa8ab527f2
  1. 26
      ext/json/json.c
  2. 22
      ext/json/package.xml
  3. 2
      ext/json/php_json.h

26
ext/json/json.c

@ -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, ',');
}
}
}
}

22
ext/json/package.xml

@ -18,10 +18,11 @@
<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>
@ -39,6 +40,13 @@
<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>
@ -129,6 +137,14 @@
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>
<!--

2
ext/json/php_json.h

@ -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

Loading…
Cancel
Save