View Ticket
Ticket Hash: | ce9ff32a532dc79bf18975506c8ccc87ccd1983b | |||
Title: | json_encode does not escape double quotes - creates invalid JSON | |||
Status: | Closed | Type: | Code_Defect | |
Severity: | Critical | Priority: | Immediate | |
Subsystem: | Resolution: | Fixed | ||
Last Modified: | 2014-04-24 02:18:35 | |||
Version Found In: | 18.1 | |||
Description: | ||||
Double quotes " are not escaped properly.
A quick fix for upgrade.php version 18.1 Line 798 is: "\"" => $options & JSON_HEX_QUOT ? "\\u0022" : "\"", Should be "\"" => $options & JSON_HEX_QUOT ? "\\u0022" : "\\\"", You can see this clearly by looking at line 788: "\"" => "\\\"", I applied the fix myself and it works fine now. Sample code: <?php $arr = array("my \"quoted\" string"); echo json_encode($arr); ?> Expected output (verified using php 5.4.7) ["my \"quoted\" string"] Actual output (wrong – invalid JSON) ["my "quoted" string"] Thanks for the very useful library! Adam Fraser-Kruck | ||||
User Comments: | ||||
mario added on 2014-04-24 02:18:35:
This was obviously introduced with the JSON_ quoting flags. Fixed meanwhile. Thanks for the help! |