Mantis - Quercus
Viewing Issue Advanced Details
3189 minor always 12-17-08 23:45 12-18-08 09:35
koreth  
nam  
normal  
closed 4.0.0  
fixed  
none    
none 4.0.0  
0003189: json_decode fails on primitive values
<?php
print_r(json_decode('5'));

Regular PHP prints "5". Quercus prints "Warning: error parsing '5': expected no more input [json_decode]".

The following patch seems to match PHP's behavior (though it doesn't detect numeric values, which may or may not be worth doing):

--- a/modules/quercus/src/com/caucho/quercus/lib/json/JsonDecoder.java
+++ b/modules/quercus/src/com/caucho/quercus/lib/json/JsonDecoder.java
@@ -51,6 +51,12 @@ class JsonDecoder {
 
     _isAssociative = assoc;
 
+ int c = skipWhitespace();
+ if (c != '[' && c != '{' && c != '"') {
+ return s;
+ }
+ unread();
+
     Value val = jsonDecodeImpl(env);
 
     // Should now be at end of string or have only white spaces left.

Notes
(0003671)
nam   
12-18-08 09:35   
php/4720