From:             tjerk dot meesters at muvee dot com
Operating system: n/a
PHP version:      5.2.4
PHP Bug Type:     JSON related
Bug description:  json_decode: escape characters

Description:
------------
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:
---------------
<?php

$s = '"Sir, you\\\'re an idiot!"';
var_dump(json_decode($s));
var_dump(json_decode("[$s]"));

?>


Expected result:
----------------
string(21) "Sir, you're an idiot!"
array(1) {
  [0]=>
  string(21) "Sir, you're an idiot!"
}

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


-- 
Edit bug report at http://bugs.php.net/?id=42708&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42708&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42708&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42708&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42708&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42708&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42708&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42708&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42708&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42708&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42708&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42708&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42708&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42708&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42708&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42708&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42708&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42708&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42708&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42708&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42708&r=mysqlcfg

Reply via email to