[PHP-CVS] cvs: php-src /ext/json json.c

2009-06-24 Thread Felipe Pena
felipe  Wed Jun 24 17:39:36 2009 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  - Fixed memleak when depth arg is less than zero
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.55r2=1.56diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.55 php-src/ext/json/json.c:1.56
--- php-src/ext/json/json.c:1.55Sun May 31 13:50:50 2009
+++ php-src/ext/json/json.c Wed Jun 24 17:39:36 2009
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.55 2009/05/31 13:50:50 jani Exp $ */
+/* $Id: json.c,v 1.56 2009/06/24 17:39:36 felipe Exp $ */
 
 /*
  * UTODO
@@ -544,6 +544,7 @@
 
if (depth = 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, Depth must greater 
than zero);
+   efree(utf16);
RETURN_NULL();
}
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2009-05-31 Thread Jani Taskinen
janiSun May 31 13:50:50 2009 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  - No dots in error messages
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.54r2=1.55diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.54 php-src/ext/json/json.c:1.55
--- php-src/ext/json/json.c:1.54Sun May 31 01:45:05 2009
+++ php-src/ext/json/json.c Sun May 31 13:50:50 2009
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.54 2009/05/31 01:45:05 andrei Exp $ */
+/* $Id: json.c,v 1.55 2009/05/31 13:50:50 jani Exp $ */
 
 /*
  * UTODO
@@ -456,7 +456,7 @@
smart_str_appendl(buf, d, len);
efree(d);
} else {
-   zend_error(E_WARNING, [json] 
(json_encode_r) double %.9g does not conform to the JSON spec, encoded as 0., 
dbl);
+   zend_error(E_WARNING, [json] 
(json_encode_r) double %.9g does not conform to the JSON spec, encoded as 0, 
dbl);
smart_str_appendc(buf, '0');
}
}
@@ -473,7 +473,7 @@
break;
 
default:
-   zend_error(E_WARNING, [json] (json_encode_r) type is 
unsupported, encoded as null.);
+   zend_error(E_WARNING, [json] (json_encode_r) type is 
unsupported, encoded as null);
smart_str_appendl(buf, null, 4);
break;
}
@@ -543,7 +543,7 @@
}
 
if (depth = 0) {
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, Depth must greater 
than zero.);
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, Depth must greater 
than zero);
RETURN_NULL();
}
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2009-05-30 Thread Andrei Zmievski
andrei  Sun May 31 01:45:05 2009 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Make a note.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.53r2=1.54diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.53 php-src/ext/json/json.c:1.54
--- php-src/ext/json/json.c:1.53Fri May 15 09:10:01 2009
+++ php-src/ext/json/json.c Sun May 31 01:45:05 2009
@@ -16,7 +16,13 @@
   +--+
 */
 
-/* $Id: json.c,v 1.53 2009/05/15 09:10:01 kalle Exp $ */
+/* $Id: json.c,v 1.54 2009/05/31 01:45:05 andrei Exp $ */
+
+/*
+ * UTODO
+ * - take a look at json_decode, some weird IS_STRING checks there
+ * - expose encode/decode API once that's done
+ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2009-05-15 Thread Kalle Sommer Nielsen
kalle   Fri May 15 09:10:01 2009 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Fix arginfo
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.52r2=1.53diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.52 php-src/ext/json/json.c:1.53
--- php-src/ext/json/json.c:1.52Thu May 14 22:00:38 2009
+++ php-src/ext/json/json.c Fri May 15 09:10:01 2009
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.52 2009/05/14 22:00:38 scottmac Exp $ */
+/* $Id: json.c,v 1.53 2009/05/15 09:10:01 kalle Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -57,6 +57,7 @@
 ZEND_BEGIN_ARG_INFO_EX(arginfo_json_decode, 0, 0, 1)
ZEND_ARG_INFO(0, json)
ZEND_ARG_INFO(0, assoc)
+   ZEND_ARG_INFO(0, depth)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO(arginfo_json_last_error, 0)
@@ -475,7 +476,7 @@
 }
 /* }}} */
 
-/* {{{ proto string json_encode(mixed data) U
+/* {{{ proto string json_encode(mixed data [, long options]) U
Returns the JSON representation of a value */
 static PHP_FUNCTION(json_encode)
 {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2009-05-14 Thread Scott MacVicar
scottmacThu May 14 22:00:38 2009 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Throw an error rather than silently changing to the default.
  
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.51r2=1.52diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.51 php-src/ext/json/json.c:1.52
--- php-src/ext/json/json.c:1.51Thu May 14 00:13:57 2009
+++ php-src/ext/json/json.c Thu May 14 22:00:38 2009
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.51 2009/05/14 00:13:57 scottmac Exp $ */
+/* $Id: json.c,v 1.52 2009/05/14 22:00:38 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -536,7 +536,8 @@
}
 
if (depth = 0) {
-   depth = JSON_PARSER_DEFAULT_DEPTH;
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, Depth must greater 
than zero.);
+   RETURN_NULL();
}
 
ALLOC_INIT_ZVAL(z);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c /ext/json/tests 002.phpt

2009-03-17 Thread Scott MacVicar
scottmacTue Mar 17 23:15:17 2009 UTC

  Modified files:  
/php-src/ext/json   json.c 
/php-src/ext/json/tests 002.phpt 
  Log:
  Add PHP_JSON_FORCE_OBJECT for forcing an object output of an array
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.48r2=1.49diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.48 php-src/ext/json/json.c:1.49
--- php-src/ext/json/json.c:1.48Tue Mar 10 23:39:26 2009
+++ php-src/ext/json/json.c Tue Mar 17 23:15:17 2009
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.48 2009/03/10 23:39:26 helly Exp $ */
+/* $Id: json.c,v 1.49 2009/03/17 23:15:17 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -41,6 +41,7 @@
 #define PHP_JSON_HEX_AMP   (11)
 #define PHP_JSON_HEX_APOS  (12)
 #define PHP_JSON_HEX_QUOT  (13)
+#define PHP_JSON_FORCE_OBJECT  (14)
 
 ZEND_DECLARE_MODULE_GLOBALS(json)
 
@@ -75,6 +76,7 @@
REGISTER_LONG_CONSTANT(JSON_HEX_AMP,  PHP_JSON_HEX_AMP,  CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(JSON_HEX_APOS, PHP_JSON_HEX_APOS, CONST_CS | 
CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(JSON_HEX_QUOT, PHP_JSON_HEX_QUOT, CONST_CS | 
CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(JSON_FORCE_OBJECT, PHP_JSON_FORCE_OBJECT, 
CONST_CS | CONST_PERSISTENT);
 
REGISTER_LONG_CONSTANT(JSON_ERROR_NONE, PHP_JSON_ERROR_NONE, CONST_CS 
| CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(JSON_ERROR_DEPTH, PHP_JSON_ERROR_DEPTH, 
CONST_CS | CONST_PERSISTENT);
@@ -174,7 +176,7 @@
 
if (Z_TYPE_PP(val) == IS_ARRAY) {
myht = HASH_OF(*val);
-   r = json_determine_array_type(val TSRMLS_CC);
+   r = (options  PHP_JSON_FORCE_OBJECT) ? 1 : 
json_determine_array_type(val TSRMLS_CC);
} else {
myht = Z_OBJPROP_PP(val);
r = 1;
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/002.phpt?r1=1.3r2=1.4diff_format=u
Index: php-src/ext/json/tests/002.phpt
diff -u php-src/ext/json/tests/002.phpt:1.3 php-src/ext/json/tests/002.phpt:1.4
--- php-src/ext/json/tests/002.phpt:1.3 Tue May 27 18:16:03 2008
+++ php-src/ext/json/tests/002.phpt Tue Mar 17 23:15:17 2009
@@ -8,8 +8,14 @@
 var_dump(json_encode());
 var_dump(json_encode(NULL));
 var_dump(json_encode(TRUE));
+
 var_dump(json_encode(array(=)));
 var_dump(json_encode(array(array(1;
+var_dump(json_encode(array()));
+
+var_dump(json_encode(array(=), JSON_FORCE_OBJECT));
+var_dump(json_encode(array(array(1)), JSON_FORCE_OBJECT));
+var_dump(json_encode(array(), JSON_FORCE_OBJECT));
 
 var_dump(json_encode(1));
 var_dump(json_encode(руссиш));
@@ -23,6 +29,10 @@
 string(4) true
 string(7) {:}
 string(5) [[1]]
+string(2) []
+string(7) {:}
+string(13) {0:{0:1}}
+string(2) {}
 string(1) 1
 string(38) \u0440\u0443\u0441\u0441\u0438\u0448
 Done



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2009-03-17 Thread Scott MacVicar
scottmacTue Mar 17 23:25:39 2009 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Replace magic values with a define, makes reading it a bit easier
  
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.49r2=1.50diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.49 php-src/ext/json/json.c:1.50
--- php-src/ext/json/json.c:1.49Tue Mar 17 23:15:17 2009
+++ php-src/ext/json/json.c Tue Mar 17 23:25:39 2009
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.49 2009/03/17 23:15:17 scottmac Exp $ */
+/* $Id: json.c,v 1.50 2009/03/17 23:25:39 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -43,6 +43,9 @@
 #define PHP_JSON_HEX_QUOT  (13)
 #define PHP_JSON_FORCE_OBJECT  (14)
 
+#define PHP_JSON_OUTPUT_ARRAY 0
+#define PHP_JSON_OUTPUT_OBJECT 1
+
 ZEND_DECLARE_MODULE_GLOBALS(json)
 
 /* {{{ arginfo */
@@ -165,7 +168,7 @@
}
}
 
-   return 0;
+   return PHP_JSON_OUTPUT_ARRAY;
 }
 /* }}} */
 
@@ -176,10 +179,10 @@
 
if (Z_TYPE_PP(val) == IS_ARRAY) {
myht = HASH_OF(*val);
-   r = (options  PHP_JSON_FORCE_OBJECT) ? 1 : 
json_determine_array_type(val TSRMLS_CC);
+   r = (options  PHP_JSON_FORCE_OBJECT) ? PHP_JSON_OUTPUT_OBJECT 
: json_determine_array_type(val TSRMLS_CC);
} else {
myht = Z_OBJPROP_PP(val);
-   r = 1;
+   r = PHP_JSON_OUTPUT_OBJECT;
}
 
if (myht  myht-nApplyCount  1) {
@@ -188,7 +191,7 @@
return;
}
 
-   if (r == 0) {
+   if (r == PHP_JSON_OUTPUT_ARRAY) {
smart_str_appendc(buf, '[');
} else {
smart_str_appendc(buf, '{');
@@ -218,7 +221,7 @@
tmp_ht-nApplyCount++;
}
 
-   if (r == 0) {
+   if (r == PHP_JSON_OUTPUT_ARRAY) {
if (need_comma) {
smart_str_appendc(buf, ',');
} else {
@@ -226,7 +229,7 @@
}
  
json_encode_r(buf, *data, options 
TSRMLS_CC);
-   } else if (r == 1) {
+   } else if (r == PHP_JSON_OUTPUT_OBJECT) {
if (i == HASH_KEY_IS_STRING || i == 
HASH_KEY_IS_UNICODE) {
if (key.s[0] == '\0'  
Z_TYPE_PP(val) == IS_OBJECT) {
/* Skip protected and 
private members. */
@@ -269,7 +272,7 @@
}
}
 
-   if (r == 0) {
+   if (r == PHP_JSON_OUTPUT_ARRAY) {
smart_str_appendc(buf, ']');
} else {
smart_str_appendc(buf, '}');



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2008-12-24 Thread Scott MacVicar
scottmacWed Dec 24 18:09:01 2008 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Make sure we clear out the error when the scalar version decoding works.
  
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.45r2=1.46diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.45 php-src/ext/json/json.c:1.46
--- php-src/ext/json/json.c:1.45Fri Dec 19 02:00:59 2008
+++ php-src/ext/json/json.c Wed Dec 24 18:09:00 2008
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.45 2008/12/19 02:00:59 scottmac Exp $ */
+/* $Id: json.c,v 1.46 2008/12/24 18:09:00 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -551,6 +551,8 @@
 
if (str_len == 4) {
if (!strcasecmp(str.s, null)) {
+   /* We need to explicitly clear the error 
because its an actual NULL and not an error */
+   jp-error_code = PHP_JSON_ERROR_NONE;
RETVAL_NULL();
} else if (!strcasecmp(str.s, true)) {
RETVAL_BOOL(1);
@@ -566,6 +568,10 @@
RETVAL_DOUBLE(d);
}
}
+
+   if (Z_TYPE_P(return_value) != IS_NULL) {
+   jp-error_code = PHP_JSON_ERROR_NONE;
+   }
}
else
{
@@ -578,6 +584,8 @@
 
if (str_len == 4) {
if (ZEND_U_CASE_EQUAL(IS_UNICODE, str, str_len, null, 
sizeof(null)-1)) {
+   /* We need to explicitly clear the error 
because its an actual NULL and not an error */
+   jp-error_code = PHP_JSON_ERROR_NONE;
RETVAL_NULL();
} else if (ZEND_U_CASE_EQUAL(IS_UNICODE, str, str_len, 
true, sizeof(true)-1)) {
RETVAL_BOOL(1);
@@ -593,6 +601,10 @@
RETVAL_DOUBLE(d);
}
}
+   
+   if (Z_TYPE_P(return_value) != IS_NULL) {
+   jp-error_code = PHP_JSON_ERROR_NONE;
+   }
}
 
FREE_ZVAL(z);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c /ext/json/tests 001.phpt bug41504.phpt bug42090.phpt fail001.phpt

2008-12-12 Thread Scott MacVicar
scottmacFri Dec 12 23:17:44 2008 UTC

  Modified files:  
/php-src/ext/json   json.c 
/php-src/ext/json/tests 001.phpt bug41504.phpt bug42090.phpt 
fail001.phpt 
  Log:
  Fix bug #45989 - json_decode() doesn't return NULL on certain invalid strings
  
  
  http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.42r2=1.43diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.42 php-src/ext/json/json.c:1.43
--- php-src/ext/json/json.c:1.42Mon Nov 17 11:26:21 2008
+++ php-src/ext/json/json.c Fri Dec 12 23:17:44 2008
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.42 2008/11/17 11:26:21 felipe Exp $ */
+/* $Id: json.c,v 1.43 2008/12/12 23:17:44 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -544,13 +544,7 @@
RETURN_DOUBLE(d);
}
}
-   if (str_len  1  *str.s == ''  str.s[str_len-1] == '') {
-   RETURN_STRINGL(str.s+1, str_len-2, 1);
-   } else if (*str.s == '{' || *str.s == '[') { /* invalid JSON 
string */
-   RETURN_NULL();
-   } else {
-   RETURN_STRINGL(str.s, str_len, 1);
-   }
+   RETURN_NULL();
}
else
{
@@ -577,13 +571,7 @@
RETURN_DOUBLE(d);
}
}
-   if (str_len  1  *str.u == 0x22 /*''*/  str.u[str_len-1] 
== 0x22 /*''*/) {
-   RETURN_UNICODEL(str.u+1, str_len-2, 1);
-   } else if (*str.u == 0x7b /*'{'*/ || *str.u == 0x5b /*'['*/ ) { 
/* invalid JSON string */
-   RETURN_NULL();
-   } else {
-   RETURN_UNICODEL(str.u, str_len, 1);
-   }
+   RETURN_NULL();
}
 }
 /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/001.phpt?r1=1.5r2=1.6diff_format=u
Index: php-src/ext/json/tests/001.phpt
diff -u php-src/ext/json/tests/001.phpt:1.5 php-src/ext/json/tests/001.phpt:1.6
--- php-src/ext/json/tests/001.phpt:1.5 Tue May 27 18:16:03 2008
+++ php-src/ext/json/tests/001.phpt Fri Dec 12 23:17:44 2008
@@ -31,12 +31,12 @@
 NULL
 NULL
 NULL
-unicode(1) .
-unicode(1) .
-unicode(3) ?
-unicode(1) ;
-unicode(6) руссиш
-unicode(4) blah
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
 NULL
 object(stdClass)#%d (1) {
   [utest]=
@@ -66,6 +66,6 @@
 unicode(0) 
   }
 }
-unicode(16) { : { :  }
-unicode(16) { : :  } }
+NULL
+NULL
 Done
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug41504.phpt?r1=1.2r2=1.3diff_format=u
Index: php-src/ext/json/tests/bug41504.phpt
diff -u php-src/ext/json/tests/bug41504.phpt:1.2 
php-src/ext/json/tests/bug41504.phpt:1.3
--- php-src/ext/json/tests/bug41504.phpt:1.2Tue Jul 22 14:14:31 2008
+++ php-src/ext/json/tests/bug41504.phptFri Dec 12 23:17:44 2008
@@ -13,19 +13,19 @@
 ?
 --EXPECT-- 
 array(1) {
-  []=
-  string(5) value
+  [u]=
+  unicode(5) value
 }
 array(2) {
-  []=
-  string(5) value
-  [key]=
-  string(5) value
+  [u]=
+  unicode(5) value
+  [ukey]=
+  unicode(5) value
 }
 array(2) {
-  [key]=
-  string(5) value
-  []=
-  string(5) value
+  [ukey]=
+  unicode(5) value
+  [u]=
+  unicode(5) value
 }
 Done
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug42090.phpt?r1=1.3r2=1.4diff_format=u
Index: php-src/ext/json/tests/bug42090.phpt
diff -u php-src/ext/json/tests/bug42090.phpt:1.3 
php-src/ext/json/tests/bug42090.phpt:1.4
--- php-src/ext/json/tests/bug42090.phpt:1.3Tue May 27 18:16:03 2008
+++ php-src/ext/json/tests/bug42090.phptFri Dec 12 23:17:44 2008
@@ -16,10 +16,9 @@
 ?
 --EXPECT--
 unicode(0) 
-unicode(5) ...
-unicode(1) 
-unicode(2) 
+NULL
+NULL
+NULL
 string(4) \
 unicode(1) 
 unicode(2) 
-
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/fail001.phpt?r1=1.7r2=1.8diff_format=u
Index: php-src/ext/json/tests/fail001.phpt
diff -u php-src/ext/json/tests/fail001.phpt:1.7 
php-src/ext/json/tests/fail001.phpt:1.8
--- php-src/ext/json/tests/fail001.phpt:1.7 Thu Jul 31 11:49:19 2008
+++ php-src/ext/json/tests/fail001.phpt Fri Dec 12 23:17:44 2008
@@ -50,116 +50,116 @@
 unicode(58) A JSON payload should be an object or array, not a string.
 Testing: [Unclosed array
 AS OBJECT
-unicode(17) [Unclosed array
+NULL
 AS ARRAY
-unicode(17) [Unclosed array
+NULL
 Testing: {unquoted_key: keys must be quoted}
 AS OBJECT
-unicode(36) {unquoted_key: keys must be quoted}
+NULL
 AS ARRAY
-unicode(36) {unquoted_key: keys must be quoted}
+NULL
 Testing: [extra comma,]
 AS OBJECT
-unicode(16) [extra comma,]
+NULL
 AS ARRAY
-unicode(16) [extra comma,]
+NULL
 Testing: [double extra comma,,]
 AS OBJECT
-unicode(24) [double extra comma,,]
+NULL
 AS ARRAY
-unicode(24) [double extra comma,,]
+NULL
 Testing: [   , -- missing value]
 AS OBJECT

[PHP-CVS] cvs: php-src /ext/json json.c

2008-10-01 Thread Felipe Pena
felipe  Thu Oct  2 03:30:54 2008 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  - Fixed bug #46215 (json_encode mutates its parameter and has some 
class-specific state)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.38r2=1.39diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.38 php-src/ext/json/json.c:1.39
--- php-src/ext/json/json.c:1.38Tue Jul 22 17:06:00 2008
+++ php-src/ext/json/json.c Thu Oct  2 03:30:54 2008
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.38 2008/07/22 17:06:00 jani Exp $ */
+/* $Id: json.c,v 1.39 2008/10/02 03:30:54 felipe Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -211,6 +211,9 @@
if (i == HASH_KEY_IS_STRING || i == 
HASH_KEY_IS_UNICODE) {
if (key.s[0] == '\0'  
Z_TYPE_PP(val) == IS_OBJECT) {
/* Skip protected and 
private members. */
+   if (tmp_ht) {
+   
tmp_ht-nApplyCount--;
+   }
continue;
}
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2008-07-22 Thread Jani Taskinen
janiTue Jul 22 15:30:33 2008 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  ws + cs + sync with PHP_5_3
  http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.36r2=1.37diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.36 php-src/ext/json/json.c:1.37
--- php-src/ext/json/json.c:1.36Fri Jun 27 19:17:29 2008
+++ php-src/ext/json/json.c Tue Jul 22 15:30:33 2008
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.36 2008/06/27 19:17:29 felipe Exp $ */
+/* $Id: json.c,v 1.37 2008/07/22 15:30:33 jani Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -30,6 +30,10 @@
 #include JSON_parser.h
 #include php_json.h
 
+static PHP_MINFO_FUNCTION(json);
+static PHP_FUNCTION(json_encode);
+static PHP_FUNCTION(json_decode);
+
 static const char digits[] = 0123456789abcdef;
 
 #define PHP_JSON_HEX_TAG   (10)
@@ -54,10 +58,10 @@
  *
  * Every user visible function must have an entry in json_functions[].
  */
-const function_entry json_functions[] = {
-PHP_FE(json_encode, arginfo_json_encode)
-PHP_FE(json_decode, arginfo_json_decode)
-   {NULL, NULL, NULL}  /* Must be the last line in json_functions[] */
+static const function_entry json_functions[] = {
+   PHP_FE(json_encode, arginfo_json_encode)
+   PHP_FE(json_decode, arginfo_json_decode)
+   {NULL, NULL, NULL}
 };
 /* }}} */
 
@@ -100,7 +104,7 @@
 
 /* {{{ PHP_MINFO_FUNCTION
  */
-PHP_MINFO_FUNCTION(json)
+static PHP_MINFO_FUNCTION(json)
 {
php_info_print_table_start();
php_info_print_table_row(2, json support, enabled);
@@ -165,17 +169,16 @@
return;
}
 
-   if (r == 0)
-   {
+   if (r == 0) {
smart_str_appendc(buf, '[');
-   }
-   else
-   {
+   } else {
smart_str_appendc(buf, '{');
}
 
i = myht ? zend_hash_num_elements(myht) : 0;
-   if (i  0) {
+
+   if (i  0)
+   {
zstr key;
zval **data;
ulong index;
@@ -205,8 +208,7 @@
  
json_encode_r(buf, *data, options 
TSRMLS_CC);
} else if (r == 1) {
-   if (i == HASH_KEY_IS_STRING ||
-   i == HASH_KEY_IS_UNICODE) {
+   if (i == HASH_KEY_IS_STRING || i == 
HASH_KEY_IS_UNICODE) {
if (key.s[0] == '\0'  
Z_TYPE_PP(val) == IS_OBJECT) {
/* Skip protected and 
private members. */
continue;
@@ -218,7 +220,7 @@
need_comma = 1;
}
 
-   json_escape_string(buf, key, 
key_len - 1, (i==HASH_KEY_IS_UNICODE)?IS_UNICODE:IS_STRING, options TSRMLS_CC);
+   json_escape_string(buf, key, 
key_len - 1, (i == HASH_KEY_IS_UNICODE) ? IS_UNICODE : IS_STRING, options 
TSRMLS_CC);
smart_str_appendc(buf, ':');
 
json_encode_r(buf, *data, 
options TSRMLS_CC);
@@ -228,7 +230,7 @@
} else {
need_comma = 1;
}
-   
+
smart_str_appendc(buf, '');
smart_str_append_long(buf, 
(long) index);
smart_str_appendc(buf, '');
@@ -245,12 +247,9 @@
}
}
 
-   if (r == 0)
-   {
+   if (r == 0) {
smart_str_appendc(buf, ']');
-   }
-   else
-   {
+   } else {
smart_str_appendc(buf, '}');
}
 }
@@ -264,25 +263,23 @@
unsigned short us;
unsigned short *utf16;
 
-   if (len == 0)
-   {
+   if (len == 0) {
smart_str_appendl(buf, \\, 2);
return;
}
 
if (type == IS_UNICODE) {
utf16 = (unsigned short *) s.u;
-   } else {
+   } else {
utf16 = (unsigned short *) safe_emalloc(len, sizeof(unsigned 
short), 0);
 
len = utf8_to_utf16(utf16, s.s, len);
-   if (len = 0)
-   {
+   if (len = 0) {
if (utf16) {
efree(utf16);
}
-   if(len  0) {
-   if(!PG(display_errors)) {
+   

[PHP-CVS] cvs: php-src /ext/json json.c

2008-07-22 Thread Jani Taskinen
janiTue Jul 22 17:06:00 2008 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  MFB:- Fixed bug #38680 (Added missing handling of basic types in json_decode)
  # This was claimed to be in HEAD but wasn't..some commit reverted it or
  # someone didn't check for real..
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.37r2=1.38diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.37 php-src/ext/json/json.c:1.38
--- php-src/ext/json/json.c:1.37Tue Jul 22 15:30:33 2008
+++ php-src/ext/json/json.c Tue Jul 22 17:06:00 2008
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.37 2008/07/22 15:30:33 jani Exp $ */
+/* $Id: json.c,v 1.38 2008/07/22 17:06:00 jani Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -545,6 +545,8 @@
}
if (str_len  1  *str.s == ''  str.s[str_len-1] == '') {
RETURN_STRINGL(str.s+1, str_len-2, 1);
+   } else if (*str.s == '{' || *str.s == '[') { /* invalid JSON 
string */
+   RETURN_NULL();
} else {
RETURN_STRINGL(str.s, str_len, 1);
}
@@ -576,6 +578,8 @@
}
if (str_len  1  *str.u == 0x22 /*''*/  str.u[str_len-1] 
== 0x22 /*''*/) {
RETURN_UNICODEL(str.u+1, str_len-2, 1);
+   } else if (*str.u == 0x7b /*'{'*/ || *str.u == 0x5b /*'['*/ ) { 
/* invalid JSON string */
+   RETURN_NULL();
} else {
RETURN_UNICODEL(str.u, str_len, 1);
}



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2008-01-30 Thread Dmitry Stogov
dmitry  Wed Jan 30 08:10:28 2008 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  ZTS fix
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.34r2=1.35diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.34 php-src/ext/json/json.c:1.35
--- php-src/ext/json/json.c:1.34Wed Jan 30 03:21:30 2008
+++ php-src/ext/json/json.c Wed Jan 30 08:10:28 2008
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.34 2008/01/30 03:21:30 stas Exp $ */
+/* $Id: json.c,v 1.35 2008/01/30 08:10:28 dmitry Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -97,7 +97,7 @@
 /* }}} */
 
 static void json_encode_r(smart_str *buf, zval *val, int options TSRMLS_DC);
-static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type, int options);
+static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type, int options TSRMLS_DC);
 
 static int json_determine_array_type(zval **val TSRMLS_DC) /* {{{ */
 {
@@ -205,7 +205,7 @@
need_comma = 1;
}
 
-   json_escape_string(buf, key, 
key_len - 1, (i==HASH_KEY_IS_UNICODE)?IS_UNICODE:IS_STRING, options);
+   json_escape_string(buf, key, 
key_len - 1, (i==HASH_KEY_IS_UNICODE)?IS_UNICODE:IS_STRING, options TSRMLS_CC);
smart_str_appendc(buf, ':');
 
json_encode_r(buf, *data, 
options TSRMLS_CC);
@@ -245,7 +245,7 @@
 
 #define REVERSE16(us) (((us  0xf)  12) | (((us  4)  0xf)  8) | (((us 
 8)  0xf)  4) | ((us  12)  0xf))
 
-static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type, int options) /* {{{ */
+static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type, int options TSRMLS_DC) /* {{{ */
 {
int pos = 0;
unsigned short us;
@@ -437,7 +437,7 @@
break;
case IS_STRING:
case IS_UNICODE:
-   json_escape_string(buf, Z_UNIVAL_P(val), 
Z_UNILEN_P(val), Z_TYPE_P(val), options);
+   json_escape_string(buf, Z_UNIVAL_P(val), 
Z_UNILEN_P(val), Z_TYPE_P(val), options TSRMLS_CC);
break;
case IS_ARRAY:
case IS_OBJECT:

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c utf8_to_utf16.c /ext/json/tests bug43941.phpt

2008-01-29 Thread Stanislav Malyshev
stasWed Jan 30 03:21:30 2008 UTC

  Modified files:  
/php-src/ext/json   json.c utf8_to_utf16.c 
/php-src/ext/json/tests bug43941.phpt 
  Log:
  fix #43941: invalid utf-8 not accepted
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.33r2=1.34diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.33 php-src/ext/json/json.c:1.34
--- php-src/ext/json/json.c:1.33Mon Dec 31 07:12:10 2007
+++ php-src/ext/json/json.c Wed Jan 30 03:21:30 2008
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.33 2007/12/31 07:12:10 sebastian Exp $ */
+/* $Id: json.c,v 1.34 2008/01/30 03:21:30 stas Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -265,12 +265,17 @@
len = utf8_to_utf16(utf16, s.s, len);
if (len = 0)
{
-   if (utf16)
-   {
+   if (utf16) {
efree(utf16);
}
-
-   smart_str_appendl(buf, \\, 2);
+   if(len  0) {
+   if(!PG(display_errors)) {
+   php_error_docref(NULL TSRMLS_CC, 
E_WARNING, Invalid UTF-8 sequence in argument);
+   }
+   smart_str_appendl(buf, null, 4);
+   } else {
+   smart_str_appendl(buf, \\, 2);
+   }
return;
}
}
http://cvs.php.net/viewvc.cgi/php-src/ext/json/utf8_to_utf16.c?r1=1.2r2=1.3diff_format=u
Index: php-src/ext/json/utf8_to_utf16.c
diff -u php-src/ext/json/utf8_to_utf16.c:1.2 
php-src/ext/json/utf8_to_utf16.c:1.3
--- php-src/ext/json/utf8_to_utf16.c:1.2Thu Jul 12 09:55:41 2007
+++ php-src/ext/json/utf8_to_utf16.cWed Jan 30 03:21:30 2008
@@ -39,7 +39,7 @@
for (;;) {
c = utf8_decode_next(utf8);
if (c  0) {
-   return UTF8_END ? the_index : UTF8_ERROR;
+   return (c == UTF8_END) ? the_index : UTF8_ERROR;
}
if (c  0x1) {
w[the_index] = (unsigned short)c;
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug43941.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/bug43941.phpt
diff -u /dev/null php-src/ext/json/tests/bug43941.phpt:1.2
--- /dev/null   Wed Jan 30 03:21:30 2008
+++ php-src/ext/json/tests/bug43941.phptWed Jan 30 03:21:30 2008
@@ -0,0 +1,21 @@
+--TEST--
+Bug #43941 (json_encode() invalid UTF-8)
+--SKIPIF--
+?php if (!extension_loaded(json)) print skip; ?
+--FILE--
+?php
+
+var_dump(json_encode(abc));
+var_dump(json_encode(ab\xE0));
+var_dump(json_encode(ab\xE0c));
+var_dump(json_encode(array(ab\xE0, ab\xE0c, abc)));
+
+echo Done\n;
+?
+--EXPECTF--
+string(5) abc
+string(4) null
+string(4) null
+string(17) [null,null,abc]
+Done
+

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c /ext/json/tests 006.phpt

2007-12-16 Thread Sara Golemon
pollita Mon Dec 17 07:48:21 2007 UTC

  Added files: 
/php-src/ext/json/tests 006.phpt 

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Add support for encoding options
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.31r2=1.32diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.31 php-src/ext/json/json.c:1.32
--- php-src/ext/json/json.c:1.31Mon Oct  1 15:25:01 2007
+++ php-src/ext/json/json.c Mon Dec 17 07:48:21 2007
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.31 2007/10/01 15:25:01 iliaa Exp $ */
+/* $Id: json.c,v 1.32 2007/12/17 07:48:21 pollita Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -32,6 +32,11 @@
 
 static const char digits[] = 0123456789abcdef;
 
+#define PHP_JSON_HEX_TAG   (10)
+#define PHP_JSON_HEX_AMP   (11)
+#define PHP_JSON_HEX_APOS  (12)
+#define PHP_JSON_HEX_QUOT  (13)
+
 /* {{{ json_functions[]
  *
  * Every user visible function must have an entry in json_functions[].
@@ -43,6 +48,19 @@
 };
 /* }}} */
 
+/* {{{ MINIT */
+static PHP_MINIT_FUNCTION(json)
+{
+   REGISTER_LONG_CONSTANT(JSON_HEX_TAG,  PHP_JSON_HEX_TAG,  CONST_CS | 
CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(JSON_HEX_AMP,  PHP_JSON_HEX_AMP,  CONST_CS | 
CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(JSON_HEX_APOS, PHP_JSON_HEX_APOS, CONST_CS | 
CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(JSON_HEX_QUOT, PHP_JSON_HEX_QUOT, CONST_CS | 
CONST_PERSISTENT);
+
+   return SUCCESS;
+}
+/* }}} */
+
+
 /* {{{ json_module_entry
  */
 zend_module_entry json_module_entry = {
@@ -51,7 +69,7 @@
 #endif
json,
json_functions,
-   NULL,
+   PHP_MINIT(json),
NULL,
NULL,
NULL,
@@ -78,8 +96,8 @@
 }
 /* }}} */
 
-static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC);
-static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type);
+static void json_encode_r(smart_str *buf, zval *val, int options TSRMLS_DC);
+static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type, int options);
 
 static int json_determine_array_type(zval **val TSRMLS_DC) /* {{{ */
 {
@@ -115,7 +133,7 @@
 }
 /* }}} */
 
-static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) /* {{{ */
+static void json_encode_array(smart_str *buf, zval **val, int options 
TSRMLS_DC) /* {{{ */
 {
int i, r;
HashTable *myht;
@@ -172,7 +190,7 @@
need_comma = 1;
}
  
-   json_encode_r(buf, *data TSRMLS_CC);
+   json_encode_r(buf, *data, options 
TSRMLS_CC);
} else if (r == 1) {
if (i == HASH_KEY_IS_STRING ||
i == HASH_KEY_IS_UNICODE) {
@@ -187,10 +205,10 @@
need_comma = 1;
}
 
-   json_escape_string(buf, key, 
key_len - 1, (i==HASH_KEY_IS_UNICODE)?IS_UNICODE:IS_STRING);
+   json_escape_string(buf, key, 
key_len - 1, (i==HASH_KEY_IS_UNICODE)?IS_UNICODE:IS_STRING, options);
smart_str_appendc(buf, ':');
 
-   json_encode_r(buf, *data 
TSRMLS_CC);
+   json_encode_r(buf, *data, 
options TSRMLS_CC);
} else {
if (need_comma) {
smart_str_appendc(buf, 
',');
@@ -203,7 +221,7 @@
smart_str_appendc(buf, '');
smart_str_appendc(buf, ':');
 
-   json_encode_r(buf, *data 
TSRMLS_CC);
+   json_encode_r(buf, *data, 
options TSRMLS_CC);
}
}
 
@@ -227,7 +245,7 @@
 
 #define REVERSE16(us) (((us  0xf)  12) | (((us  4)  0xf)  8) | (((us 
 8)  0xf)  4) | ((us  12)  0xf))
 
-static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type) /* {{{ */
+static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type, int options) /* {{{ */
 {
int pos = 0;
unsigned short us;
@@ -267,7 +285,11 @@
{
case '':
{
-   smart_str_appendl(buf, \\\, 2);
+   if (options  PHP_JSON_HEX_QUOT) {
+

[PHP-CVS] cvs: php-src /ext/json json.c /main snprintf.c spprintf.c

2007-10-01 Thread Ilia Alshanetsky
iliaa   Mon Oct  1 15:25:01 2007 UTC

  Modified files:  
/php-src/main   snprintf.c spprintf.c 
/php-src/ext/json   json.c 
  Log:
  
  MFB: Fixed bug #42785 (json_encode() formats doubles according to locale
  rather then following standard syntax).
  
http://cvs.php.net/viewvc.cgi/php-src/main/snprintf.c?r1=1.59r2=1.60diff_format=u
Index: php-src/main/snprintf.c
diff -u php-src/main/snprintf.c:1.59 php-src/main/snprintf.c:1.60
--- php-src/main/snprintf.c:1.59Tue Sep  4 11:19:33 2007
+++ php-src/main/snprintf.c Mon Oct  1 15:25:01 2007
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: snprintf.c,v 1.59 2007/09/04 11:19:33 derick Exp $ */
+/* $Id: snprintf.c,v 1.60 2007/10/01 15:25:01 iliaa Exp $ */
 
 
 #include php.h
@@ -1051,6 +1051,7 @@
 
 
case 'g':
+   case 'k':
case 'G':
case 'H':
switch(modifier) {
@@ -1091,7 +1092,7 @@
lconv = localeconv();
}
 #endif
-   s = php_gcvt(fp_num, precision, 
*fmt=='H' ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', 
num_buf[1]);
+   s = php_gcvt(fp_num, precision, (*fmt 
== 'H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 
'H')?'E':'e', num_buf[1]);
if (*s == '-')
prefix_char = *s++;
else if (print_sign)
http://cvs.php.net/viewvc.cgi/php-src/main/spprintf.c?r1=1.49r2=1.50diff_format=u
Index: php-src/main/spprintf.c
diff -u php-src/main/spprintf.c:1.49 php-src/main/spprintf.c:1.50
--- php-src/main/spprintf.c:1.49Fri Aug  3 14:30:59 2007
+++ php-src/main/spprintf.c Mon Oct  1 15:25:01 2007
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: spprintf.c,v 1.49 2007/08/03 14:30:59 tony2001 Exp $ */
+/* $Id: spprintf.c,v 1.50 2007/10/01 15:25:01 iliaa Exp $ */
 
 /* This is the spprintf implementation.
  * It has emerged from apache snprintf. See original header:
@@ -690,6 +690,7 @@
 
 
case 'g':
+   case 'k':
case 'G':
case 'H':
switch(modifier) {
@@ -730,7 +731,7 @@
lconv = localeconv();
}
 #endif
-   s = php_gcvt(fp_num, precision, 
*fmt=='H' ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', 
num_buf[1]);
+   s = php_gcvt(fp_num, precision, 
(*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 
'H')?'E':'e', num_buf[1]);
if (*s == '-')
prefix_char = *s++;
else if (print_sign)
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.30r2=1.31diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.30 php-src/ext/json/json.c:1.31
--- php-src/ext/json/json.c:1.30Thu Sep 27 18:28:39 2007
+++ php-src/ext/json/json.c Mon Oct  1 15:25:01 2007
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.30 2007/09/27 18:28:39 dmitry Exp $ */
+/* $Id: json.c,v 1.31 2007/10/01 15:25:01 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -363,9 +363,9 @@
double dbl = Z_DVAL_P(val);
 
if (!zend_isinf(dbl)  !zend_isnan(dbl)) {
-   len = spprintf(d, 0, %.*g, (int) EG(precision), dbl);
-   smart_str_appendl(buf, d, len);
-   efree(d);
+   len = spprintf(d, 0, %.*k, (int) 
EG(precision), dbl);
+   smart_str_appendl(buf, d, len);
+   efree(d);
} else {
zend_error(E_WARNING, [json] 
(json_encode_r) double %.9g does not conform to the JSON spec, encoded as 0., 
dbl);
smart_str_appendc(buf, '0');

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c /ext/json/tests bug42090.phpt

2007-07-24 Thread Hannes Magnusson
bjori   Tue Jul 24 22:54:26 2007 UTC

  Added files: 
/php-src/ext/json/tests bug42090.phpt 

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Fixed bug#42090 (json_decode causes segmentation fault)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.27r2=1.28diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.27 php-src/ext/json/json.c:1.28
--- php-src/ext/json/json.c:1.27Wed Jun 13 17:10:06 2007
+++ php-src/ext/json/json.c Tue Jul 24 22:54:26 2007
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.27 2007/06/13 17:10:06 iliaa Exp $ */
+/* $Id: json.c,v 1.28 2007/07/24 22:54:26 bjori Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -485,7 +485,7 @@
RETURN_DOUBLE(d);
}
}
-   if (*str.s == '' || str.s[str_len] == '') {
+   if (str_len  1  *str.s == ''  str.s[str_len-1] == '') {
RETURN_STRINGL(str.s+1, str_len-2, 1);
} else {
RETURN_STRINGL(str.s, str_len, 1);
@@ -514,7 +514,7 @@
RETURN_DOUBLE(d);
}
}
-   if (*str.u == 0x22 /*''*/ || str.u[str_len] == 0x22 /*''*/) {
+   if (str_len  1  *str.u == 0x22 /*''*/  str.u[str_len-1] 
== 0x22 /*''*/) {
RETURN_UNICODEL(str.u+1, str_len-2, 1);
} else {
RETURN_UNICODEL(str.u, str_len, 1);

http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug42090.phpt?view=markuprev=1.1
Index: php-src/ext/json/tests/bug42090.phpt
+++ php-src/ext/json/tests/bug42090.phpt
--TEST--
Bug#42090 (json_decode causes segmentation fault)
--SKIPIF--
?php if (!extension_loaded(json)) print skip; ?
--FILE--
?php
var_dump(
json_decode(''),
json_decode('...'),
json_decode(''),
json_decode(''),
json_encode(''),
json_decode(json_encode('')),
json_decode(json_encode(''))
);
?
--EXPECT--
string(0) 
string(5) ...
string(1) 
string(2) 
string(4) \
string(1) 
string(2) 
--UEXPECT--
unicode(0) 
unicode(5) ...
unicode(1) 
unicode(2) 
string(4) \
unicode(1) 
unicode(2) 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2007-06-04 Thread Ilia Alshanetsky
iliaa   Mon Jun  4 23:52:34 2007 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  
  MFB: Fixed bug #41567 (json_encode() double conversion is inconsistent with
  PHP).
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.25r2=1.26diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.25 php-src/ext/json/json.c:1.26
--- php-src/ext/json/json.c:1.25Mon Apr 23 10:48:13 2007
+++ php-src/ext/json/json.c Mon Jun  4 23:52:34 2007
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.25 2007/04/23 10:48:13 tony2001 Exp $ */
+/* $Id: json.c,v 1.26 2007/06/04 23:52:34 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -363,7 +363,7 @@
 double dbl = Z_DVAL_P(val);
 
 if (!zend_isinf(dbl)  !zend_isnan(dbl)) {
-len = spprintf(d, 0, %.9g, dbl);
+   len = spprintf(d, 0, %.*g, (int) EG(precision), dbl);
 if (d) {
 if (dbl  LONG_MAX  !memchr(d, '.', len)) {
 smart_str_append_unsigned(buf, (unsigned 
long)Z_DVAL_P(val));

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c /ext/json/tests 002.phpt bug41034.phpt bug41067.phpt

2007-04-23 Thread Antony Dovgal
tony2001Mon Apr 23 10:48:13 2007 UTC

  Modified files:  
/php-src/ext/json   json.c 
/php-src/ext/json/tests bug41034.phpt bug41067.phpt 002.phpt 
  Log:
  MFB fix for #41034
  add missing tests
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.24r2=1.25diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.24 php-src/ext/json/json.c:1.25
--- php-src/ext/json/json.c:1.24Mon Apr 16 16:52:20 2007
+++ php-src/ext/json/json.c Mon Apr 23 10:48:13 2007
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.24 2007/04/16 16:52:20 andrei Exp $ */
+/* $Id: json.c,v 1.25 2007/04/23 10:48:13 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -176,7 +176,7 @@
 } else if (r == 1) {
 if (i == HASH_KEY_IS_STRING ||
i == HASH_KEY_IS_UNICODE) {
-if (key.s[0] == '\0') {
+if (key.s[0] == '\0'  Z_TYPE_PP(val) == IS_OBJECT) {
 /* Skip protected and private members. */
 continue;
 }
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug41034.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/bug41034.phpt
diff -u /dev/null php-src/ext/json/tests/bug41034.phpt:1.2
--- /dev/null   Mon Apr 23 10:48:13 2007
+++ php-src/ext/json/tests/bug41034.phptMon Apr 23 10:48:13 2007
@@ -0,0 +1,12 @@
+--TEST--
+Bug #41034 (json_encode() ignores null byte started keys in arrays)
+--SKIPIF--
+?php if (!extension_loaded(json)) print skip; ?
+--FILE--
+?php
+echo json_encode(array(0,\0ab=1,\0null-prefixed value));
+echo \nDone\n;
+?
+--EXPECT--
+{0:0,\uab:1,1:\unull-prefixed value}
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug41067.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/bug41067.phpt
diff -u /dev/null php-src/ext/json/tests/bug41067.phpt:1.2
--- /dev/null   Mon Apr 23 10:48:13 2007
+++ php-src/ext/json/tests/bug41067.phptMon Apr 23 10:48:13 2007
@@ -0,0 +1,23 @@
+--TEST--
+Bug #41067 (json_encode() problem with UTF-16 input)
+--SKIPIF--
+?php if (!extension_loaded(json)) print skip; ?
+--FILE--
+?php
+
+$single_barline = \360\235\204\200;
+$array = array($single_barline);
+var_dump(bin2hex((binary)$single_barline));
+
+$json = json_encode($array);
+$json_decoded = json_decode($json, true);
+
+var_dump(bin2hex((binary)$json_decoded[0]));
+
+?
+--EXPECT--
+string(8) f09d8480
+string(8) f09d8480
+--UEXPECT--
+unicode(8) f09d8480
+unicode(8) f09d8480
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/002.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/002.phpt
diff -u php-src/ext/json/tests/002.phpt:1.1 php-src/ext/json/tests/002.phpt:1.2
--- php-src/ext/json/tests/002.phpt:1.1 Thu Jul 20 08:56:24 2006
+++ php-src/ext/json/tests/002.phpt Mon Apr 23 10:48:13 2007
@@ -21,7 +21,7 @@
 string(2) 
 string(4) null
 string(4) true
-string(2) {}
+string(7) {:}
 string(5) [[1]]
 string(1) 1
 string(38) \u0440\u0443\u0441\u0441\u0438\u0448

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c /ext/json/tests bug40503.phpt

2007-02-19 Thread Antony Dovgal
tony2001Mon Feb 19 19:44:44 2007 UTC

  Modified files:  
/php-src/ext/json   json.c 
/php-src/ext/json/tests bug40503.phpt 
  Log:
  MFB: #40503 (json_encode() value corruption on 32bit systems with overflown 
values)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.22r2=1.23diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.22 php-src/ext/json/json.c:1.23
--- php-src/ext/json/json.c:1.22Mon Jan  1 09:29:25 2007
+++ php-src/ext/json/json.c Mon Feb 19 19:44:44 2007
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.22 2007/01/01 09:29:25 sebastian Exp $ */
+/* $Id: json.c,v 1.23 2007/02/19 19:44:44 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -362,17 +362,17 @@
 int len;
 double dbl = Z_DVAL_P(val);
 
-if (!zend_isinf(dbl)  !zend_isnan(dbl))
-{
+if (!zend_isinf(dbl)  !zend_isnan(dbl)) {
 len = spprintf(d, 0, %.9g, dbl);
-if (d)
-{
-smart_str_appendl(buf, d, len);
+if (d) {
+if (dbl  LONG_MAX  !memchr(d, '.', len)) {
+smart_str_append_unsigned(buf, (unsigned 
long)Z_DVAL_P(val));
+} else {
+smart_str_appendl(buf, d, len);
+}
 efree(d);
 }
-}
-else
-{
+} else {
 zend_error(E_WARNING, [json] (json_encode_r) double %.9g 
does not conform to the JSON spec, encoded as 0., dbl);
 smart_str_appendc(buf, '0');
 }
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug40503.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/bug40503.phpt
diff -u /dev/null php-src/ext/json/tests/bug40503.phpt:1.2
--- /dev/null   Mon Feb 19 19:44:44 2007
+++ php-src/ext/json/tests/bug40503.phptMon Feb 19 19:44:44 2007
@@ -0,0 +1,19 @@
+--TEST--
+Bug #40503 (json_encode() value corruption on 32bit systems with overflown 
values)
+--SKIPIF--
+?php if (!extension_loaded(json)) print skip; ?
+--FILE--
+?php
+function show_eq($x,$y) {
+   echo $x . ($x==$y ? == : !=) . $y\n;
+}
+
+$value = 0x7FFF; #2147483647;
+show_eq($value, json_encode($value));
+$value++;
+show_eq($value, json_encode($value));
+
+?
+--EXPECT--
+2147483647 == 2147483647
+2147483648 == 2147483648

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2006-12-19 Thread Nuno Lopes
nlopess Tue Dec 19 15:01:57 2006 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  MFB: little cleanup in json_determine_array_type()
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.19r2=1.20diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.19 php-src/ext/json/json.c:1.20
--- php-src/ext/json/json.c:1.19Thu Oct 19 20:24:25 2006
+++ php-src/ext/json/json.c Tue Dec 19 15:01:57 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.19 2006/10/19 20:24:25 andrei Exp $ */
+/* $Id: json.c,v 1.20 2006/12/19 15:01:57 nlopess Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -84,14 +84,7 @@
 static int json_determine_array_type(zval **val TSRMLS_DC) /* {{{ */
 {
 int i;
-HashTable *myht;
-
-if (Z_TYPE_PP(val) == IS_ARRAY) {
-myht = HASH_OF(*val);
-} else {
-myht = Z_OBJPROP_PP(val);
-return 1;
-}
+HashTable *myht = HASH_OF(*val);
 
 i = myht ? zend_hash_num_elements(myht) : 0;
 if (i  0) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2006-10-19 Thread Antony Dovgal
tony2001Thu Oct 19 10:01:55 2006 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  fix coverity issue #262 (uninitialized variable)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.16r2=1.17diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.16 php-src/ext/json/json.c:1.17
--- php-src/ext/json/json.c:1.16Tue Oct 17 17:56:54 2006
+++ php-src/ext/json/json.c Thu Oct 19 10:01:54 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.16 2006/10/17 17:56:54 andrei Exp $ */
+/* $Id: json.c,v 1.17 2006/10/19 10:01:54 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -439,6 +439,7 @@
 
if (str_type == IS_UNICODE) {
utf16 = str.u;
+   utf16_len = str_len;
} else {
utf16 = (unsigned short *) emalloc((str_len+1) * 
sizeof(unsigned short));
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c php_json.h

2006-10-19 Thread Antony Dovgal
tony2001Thu Oct 19 10:12:19 2006 UTC

  Modified files:  
/php-src/ext/json   json.c php_json.h 
  Log:
  fix folding tags, nuke json globals
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.17r2=1.18diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.17 php-src/ext/json/json.c:1.18
--- php-src/ext/json/json.c:1.17Thu Oct 19 10:01:54 2006
+++ php-src/ext/json/json.c Thu Oct 19 10:12:19 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.17 2006/10/19 10:01:54 tony2001 Exp $ */
+/* $Id: json.c,v 1.18 2006/10/19 10:12:19 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -30,9 +30,6 @@
 #include JSON_parser.h
 #include php_json.h
 
-/* If you declare any globals in php_json.h uncomment this:
-ZEND_DECLARE_MODULE_GLOBALS(json)
-*/
 static const char digits[] = 0123456789abcdef;
 
 /* {{{ json_functions[]
@@ -84,7 +81,8 @@
 static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC);
 static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type);
 
-static int json_determine_array_type(zval **val TSRMLS_DC) {
+static int json_determine_array_type(zval **val TSRMLS_DC) /* {{{ */
+{
 int i;
 HashTable *myht;
 
@@ -122,8 +120,10 @@
 
 return 0;
 }
+/* }}} */
 
-static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) {
+static void json_encode_array(smart_str *buf, zval **val TSRMLS_DC) /* {{{ */
+{
 int i, r;
 HashTable *myht;
 
@@ -230,10 +230,11 @@
 smart_str_appendc(buf, '}');
 }
 }
+/* }}} */
 
 #define REVERSE16(us) (((us  0xf)  12) | (((us  4)  0xf)  8) | (((us 
 8)  0xf)  4) | ((us  12)  0xf))
 
-static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type)
+static void json_escape_string(smart_str *buf, zstr s, int len, zend_uchar 
type) /* {{{ */
 {
 int pos = 0;
 unsigned short us;
@@ -341,8 +342,10 @@
efree(utf16);
}
 }
+/* }}} */
 
-static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) {
+static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) /* {{{ */
+{
 switch (Z_TYPE_P(val)) {
 case IS_NULL:
 smart_str_appendl(buf, null, 4);
@@ -398,6 +401,7 @@
 
 return;
 }
+/* }}} */
 
 /* {{{ proto string json_encode(mixed data) U
Returns the JSON representation of a value */
@@ -416,6 +420,7 @@
 
 smart_str_free(buf);
 }
+/* }}} */
 
 /* {{{ proto mixed json_decode(string json [, bool assoc]) U
Decodes the JSON representation into a PHP value */
@@ -525,6 +530,7 @@
}
}
 }
+/* }}} */
 
 /*
  * Local variables:
http://cvs.php.net/viewvc.cgi/php-src/ext/json/php_json.h?r1=1.8r2=1.9diff_format=u
Index: php-src/ext/json/php_json.h
diff -u php-src/ext/json/php_json.h:1.8 php-src/ext/json/php_json.h:1.9
--- php-src/ext/json/php_json.h:1.8 Sat Mar 18 04:15:16 2006
+++ php-src/ext/json/php_json.h Thu Oct 19 10:12:19 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: php_json.h,v 1.8 2006/03/18 04:15:16 omar Exp $ */
+/* $Id: php_json.h,v 1.9 2006/10/19 10:12:19 tony2001 Exp $ */
 
 #ifndef PHP_JSON_H
 #define PHP_JSON_H
@@ -41,15 +41,8 @@
 PHP_FUNCTION(json_encode);
 PHP_FUNCTION(json_decode);
 
-#ifdef ZTS
-#define JSON_G(v) TSRMG(json_globals_id, zend_json_globals *, v)
-#else
-#define JSON_G(v) (json_globals.v)
-#endif
-
 #endif  /* PHP_JSON_H */
 
-
 /*
  * Local variables:
  * tab-width: 4

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2006-10-19 Thread Andrei Zmievski
andrei  Thu Oct 19 20:24:25 2006 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Clarify why the result of json_encode() is a binary string.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.18r2=1.19diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.18 php-src/ext/json/json.c:1.19
--- php-src/ext/json/json.c:1.18Thu Oct 19 10:12:19 2006
+++ php-src/ext/json/json.c Thu Oct 19 20:24:25 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.18 2006/10/19 10:12:19 tony2001 Exp $ */
+/* $Id: json.c,v 1.19 2006/10/19 20:24:25 andrei Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -416,6 +416,10 @@
 
 json_encode_r(buf, parameter TSRMLS_CC);
 
+   /*
+* Return as binary string, since the result is 99% likely to be just
+* echo'ed out and we want to avoid overhead of double conversion.
+*/
 ZVAL_STRINGL(return_value, buf.c, buf.len, 1);
 
 smart_str_free(buf);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2006-10-16 Thread Andrei Zmievski
andrei  Mon Oct 16 17:04:51 2006 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  Patch to support primitive types. (Ilia)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.14r2=1.15diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.14 php-src/ext/json/json.c:1.15
--- php-src/ext/json/json.c:1.14Sat Jul 22 15:23:23 2006
+++ php-src/ext/json/json.c Mon Oct 16 17:04:51 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.14 2006/07/22 15:23:23 nlopess Exp $ */
+/* $Id: json.c,v 1.15 2006/10/16 17:04:51 andrei Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -446,10 +446,35 @@
 }
 else
 {
+   double d;
+   int type;
+   long p;
+
 zval_dtor(z);
 FREE_ZVAL(z);
 efree(utf16);
-RETURN_NULL();
+
+   if (parameter_len == 4) {
+   if (!strcasecmp(parameter, null)) {
+   RETURN_NULL();
+   } else if (!strcasecmp(parameter, true)) {
+   RETURN_BOOL(1);
+   }
+   } else if (parameter_len == 5  !strcasecmp(parameter, false)) {
+   RETURN_BOOL(0);
+   }
+   if ((type = is_numeric_string(parameter, parameter_len, p, d, 0)) != 
0) {
+   if (type == IS_LONG) {
+   RETURN_LONG(p);
+   } else if (type == IS_DOUBLE) {
+   RETURN_DOUBLE(d);
+   }
+   }
+   if (*parameter == '' || parameter[parameter_len] == '') {
+   RETURN_STRINGL(parameter+1, parameter_len-2, 1);
+   } else {
+   RETURN_STRINGL(parameter, parameter_len, 1);
+   }
 }
 }
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c

2006-07-20 Thread Antony Dovgal
tony2001Thu Jul 20 07:40:41 2006 UTC

  Modified files:  
/php-src/ext/json   json.c 
  Log:
  json_escape_string() doesn't use tsrm_ls, so no need to pass it
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.10r2=1.11diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.10 php-src/ext/json/json.c:1.11
--- php-src/ext/json/json.c:1.10Wed Jul 19 16:17:56 2006
+++ php-src/ext/json/json.c Thu Jul 20 07:40:41 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.10 2006/07/19 16:17:56 iliaa Exp $ */
+/* $Id: json.c,v 1.11 2006/07/20 07:40:41 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -82,7 +82,7 @@
 /* }}} */
 
 static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC);
-static void json_escape_string(smart_str *buf, char *s, int len TSRMLS_DC);
+static void json_escape_string(smart_str *buf, char *s, int len);
 
 static int json_determine_array_type(zval **val TSRMLS_DC) {
 int i;
@@ -181,7 +181,7 @@
 need_comma = 1;
 }
 
-json_escape_string(buf, key, key_len - 1 TSRMLS_CC);
+json_escape_string(buf, key, key_len - 1);
 smart_str_appendc(buf, ':');
 
 json_encode_r(buf, *data TSRMLS_CC);
@@ -216,7 +216,7 @@
 
 #define REVERSE16(us) (((us  0xf)  12) | (((us  4)  0xf)  8) | (((us 
 8)  0xf)  4) | ((us  12)  0xf))
 
-static void json_escape_string(smart_str *buf, char *s, int len TSRMLS_DC)
+static void json_escape_string(smart_str *buf, char *s, int len)
 {
 int pos = 0;
 unsigned short us;
@@ -359,7 +359,7 @@
 }
 break;
 case IS_STRING:
-json_escape_string(buf, Z_STRVAL_P(val), Z_STRLEN_P(val) 
TSRMLS_CC);
+json_escape_string(buf, Z_STRVAL_P(val), Z_STRLEN_P(val));
 break;
 case IS_ARRAY:
 case IS_OBJECT:

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c /ext/json/tests 001.phpt 002.phpt 003.phpt 004.phpt 005.phpt

2006-07-20 Thread Antony Dovgal
tony2001Thu Jul 20 08:56:24 2006 UTC

  Added files: 
/php-src/ext/json/tests 002.phpt 003.phpt 004.phpt 005.phpt 

  Modified files:  
/php-src/ext/json   json.c 
/php-src/ext/json/tests 001.phpt 
  Log:
  add recursion protection to json_encode() and new tests
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.11r2=1.12diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.11 php-src/ext/json/json.c:1.12
--- php-src/ext/json/json.c:1.11Thu Jul 20 07:40:41 2006
+++ php-src/ext/json/json.c Thu Jul 20 08:56:24 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.11 2006/07/20 07:40:41 tony2001 Exp $ */
+/* $Id: json.c,v 1.12 2006/07/20 08:56:24 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -135,6 +135,11 @@
 r = 1;
 }
 
+if (myht  myht-nApplyCount  1) {
+php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, recursion 
detected);
+return;
+}
+
 if (r == 0)
 {
 smart_str_appendc(buf, '[');
@@ -151,6 +156,7 @@
 ulong index;
 uint key_len;
 HashPosition pos;
+HashTable *tmp_ht;
 int need_comma = 0;
 
 zend_hash_internal_pointer_reset_ex(myht, pos);
@@ -160,6 +166,11 @@
 break;
 
 if (zend_hash_get_current_data_ex(myht, (void **) data, pos) == 
SUCCESS) {
+tmp_ht = HASH_OF(*data);
+if (tmp_ht) {
+tmp_ht-nApplyCount++;
+}
+
 if (r == 0) {
 if (need_comma) {
 smart_str_appendc(buf, ',');
@@ -200,6 +211,10 @@
 json_encode_r(buf, *data TSRMLS_CC);
 }
 }
+
+if (tmp_ht) {
+tmp_ht-nApplyCount--;
+}
 }
 }
 }
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/001.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/001.phpt
diff -u php-src/ext/json/tests/001.phpt:1.1 php-src/ext/json/tests/001.phpt:1.2
--- php-src/ext/json/tests/001.phpt:1.1 Thu Jul 20 08:23:45 2006
+++ php-src/ext/json/tests/001.phpt Thu Jul 20 08:56:24 2006
@@ -1,5 +1,7 @@
 --TEST--
 json_decode() tests
+--SKIPIF--
+?php if (!extension_loaded(json)) print skip; ?
 --FILE--
 ?php
 

http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/002.phpt?view=markuprev=1.1
Index: php-src/ext/json/tests/002.phpt
+++ php-src/ext/json/tests/002.phpt
--TEST--
json_encode() tests
--SKIPIF--
?php if (!extension_loaded(json)) print skip; ?
--FILE--
?php

var_dump(json_encode());
var_dump(json_encode(NULL));
var_dump(json_encode(TRUE));
var_dump(json_encode(array(=)));
var_dump(json_encode(array(array(1;

var_dump(json_encode(1));
var_dump(json_encode(руссиш));


echo Done\n;
?
--EXPECTF-- 
string(2) 
string(4) null
string(4) true
string(2) {}
string(5) [[1]]
string(1) 1
string(38) \u0440\u0443\u0441\u0441\u0438\u0448
Done

http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/003.phpt?view=markuprev=1.1
Index: php-src/ext/json/tests/003.phpt
+++ php-src/ext/json/tests/003.phpt
--TEST--
json_encode()  endless loop - 1
--SKIPIF--
?php if (!extension_loaded(json)) print skip; ?
--FILE--
?php

$a = array();
$a[] = $a;

var_dump($a);
var_dump(json_encode($a));

echo Done\n;
?
--EXPECTF-- 
array(1) {
  [0]=
  array(1) {
[0]=
array(1) {
  [0]=
  *RECURSION*
}
  }
}

Catchable fatal error: json_encode(): recursion detected in %s on line %d

http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/004.phpt?view=markuprev=1.1
Index: php-src/ext/json/tests/004.phpt
+++ php-src/ext/json/tests/004.phpt
--TEST--
json_encode()  endless loop - 2
--SKIPIF--
?php if (!extension_loaded(json)) print skip; ?
--FILE--
?php

$a = new stdclass;
$a-prop = $a;

var_dump($a);
var_dump(json_encode($a));

echo Done\n;
?
--EXPECTF-- 
object(stdClass)#%d (1) {
  [prop]=
  object(stdClass)#%d (1) {
[prop]=
*RECURSION*
  }
}

Catchable fatal error: json_encode(): recursion detected in %s on line %d

http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/005.phpt?view=markuprev=1.1
Index: php-src/ext/json/tests/005.phpt
+++ php-src/ext/json/tests/005.phpt
--TEST--
json_encode()  endless loop - 3
--SKIPIF--
?php if (!extension_loaded(json)) print skip; ?
--FILE--
?php

$a = array();
$a[] = $a;

var_dump($a);
var_dump(json_encode($a));

echo Done\n;
?
--EXPECTF-- 
array(1) {
  [0]=
  array(1) {
[0]=
*RECURSION*
  }
}

Catchable fatal error: json_encode(): recursion detected in %s on line %d

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/json json.c /ext/json/tests 003.phpt 004.phpt 005.phpt

2006-07-20 Thread Antony Dovgal
tony2001Thu Jul 20 09:33:16 2006 UTC

  Modified files:  
/php-src/ext/json   json.c 
/php-src/ext/json/tests 003.phpt 004.phpt 005.phpt 
  Log:
  use E_WARNING on recursion and add null to the result to keep it valid
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.12r2=1.13diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.12 php-src/ext/json/json.c:1.13
--- php-src/ext/json/json.c:1.12Thu Jul 20 08:56:24 2006
+++ php-src/ext/json/json.c Thu Jul 20 09:33:15 2006
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: json.c,v 1.12 2006/07/20 08:56:24 tony2001 Exp $ */
+/* $Id: json.c,v 1.13 2006/07/20 09:33:15 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -136,7 +136,8 @@
 }
 
 if (myht  myht-nApplyCount  1) {
-php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, recursion 
detected);
+php_error_docref(NULL TSRMLS_CC, E_WARNING, recursion detected);
+smart_str_appendl(buf, null, 4);
 return;
 }
 
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/003.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/003.phpt
diff -u php-src/ext/json/tests/003.phpt:1.1 php-src/ext/json/tests/003.phpt:1.2
--- php-src/ext/json/tests/003.phpt:1.1 Thu Jul 20 08:56:24 2006
+++ php-src/ext/json/tests/003.phpt Thu Jul 20 09:33:15 2006
@@ -25,4 +25,6 @@
   }
 }
 
-Catchable fatal error: json_encode(): recursion detected in %s on line %d
+Warning: json_encode(): recursion detected in %s on line %d
+string(8) [[null]]
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/004.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/004.phpt
diff -u php-src/ext/json/tests/004.phpt:1.1 php-src/ext/json/tests/004.phpt:1.2
--- php-src/ext/json/tests/004.phpt:1.1 Thu Jul 20 08:56:24 2006
+++ php-src/ext/json/tests/004.phpt Thu Jul 20 09:33:15 2006
@@ -22,4 +22,6 @@
   }
 }
 
-Catchable fatal error: json_encode(): recursion detected in %s on line %d
+Warning: json_encode(): recursion detected in %s on line %d
+string(22) {prop:{prop:null}}
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/005.phpt?r1=1.1r2=1.2diff_format=u
Index: php-src/ext/json/tests/005.phpt
diff -u php-src/ext/json/tests/005.phpt:1.1 php-src/ext/json/tests/005.phpt:1.2
--- php-src/ext/json/tests/005.phpt:1.1 Thu Jul 20 08:56:24 2006
+++ php-src/ext/json/tests/005.phpt Thu Jul 20 09:33:15 2006
@@ -22,4 +22,6 @@
   }
 }
 
-Catchable fatal error: json_encode(): recursion detected in %s on line %d
+Warning: json_encode(): recursion detected in %s on line %d
+string(8) [[null]]
+Done

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php