|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42708 json_decode: escape characters
Submitted: 2007-09-19 10:19 UTC Modified: 2008-07-22 17:33 UTC
Avg. Score:4.8 ± 0.4
Reproduced:13 of 13 (100.0%)
Same Version:7 (53.8%)
Same OS:8 (61.5%)
From: tjerk dot meesters at muvee dot com Assigned:
Status: Wont fix Package: JSON related
PHP Version: 5.2.4 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
13 - 9 = ?
Subscribe to this entry?

 [2007-09-19 10:19 UTC] tjerk dot meesters at muvee dot com
When a single quote is being escaped, the json_decode() gives some unexpected results.

1. According to the JSON specs, the single quote is not in the list of characters that can follow the escape character (such as n, t, b, r, etc.); however, JavaScript does recognize the single quote so it would be very nice to have as a feature.

2. When wrapping a string with an escaped single quote inside an array context, the json_decode() gives up and returns NULL.

Reproduce code:

$s = '"Sir, you\\\'re an idiot!"';


Expected result:
string(21) "Sir, you're an idiot!"
array(1) {
  string(21) "Sir, you're an idiot!"

Actual result:
string(22) "Sir, you\'re an idiot!"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-23 00:45 UTC]

string(22) "Sir, you\'re an idiot!"


string(22) "Sir, you\'re an idiot!"
string(26) "["Sir, you\'re an idiot!"]"
 [2008-07-22 17:33 UTC]
1. "Fixing" this would violate the JSON spec. HEAD (aka PHP 6) also behaves the same way now as other branches.

2. NULL is returned whenever you pass invalid data to json_decode().
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 12:01:29 2024 UTC