Bug #77623 [Nab]: jsno_encode handle badly backslashes
| From: | marco dot biondi at docomodigital dot com | Date: | Fri, 15 Feb 2019 13:05:04 +0000 |
| Subject: | Bug #77623 [Nab]: jsno_encode handle badly backslashes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219594@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77623&edit=1
ID: 77623
User updated by: marco dot biondi at docomodigital dot com
Reported by: marco dot biondi at docomodigital dot com
Summary: jsno_encode handle badly backslashes
Status: Not a bug
Type: Bug
Package: Unknown/Other Function
Operating System: any
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Yes you are true, I tried to oversimplify the sample and the result is confusing. I discovered this
problem trying to forward a complex object with a proper unicode literal \u00BF inside a string
field. Even in this case the json_encode convert it in \\u00BF breaking the meaning of the initial
string
Previous Comments:
------------------------------------------------------------------------
[2019-02-15 12:45:46] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
A single backslash in a JSON string literal would be an error.
------------------------------------------------------------------------
[2019-02-15 10:07:25] marco dot biondi at docomodigital dot com
Description:
------------
---
From manual page: https://php.net/function.json-encode
---
Just look at the sample code
Test script:
---------------
<?php
$a = "Srting with a slash: \ Just a slash is that I want!";
$b = "Srting with a slash: \\ Just a slash is that I want!";
var_dump($a);
var_dump(json_encode($a));
var_dump($b);
var_dump(json_encode($b));
Expected result:
----------------
string(51) "Srting with a slash: \ Just a slash is that I want!"
string(53) ""Srting with a slash: \ Just a slash is that I want!""
string(51) "Srting with a slash: \ Just a slash is that I want!"
string(53) ""Srting with a slash: \ Just a slash is that I want!""
Actual result:
--------------
string(51) "Srting with a slash: \ Just a slash is that I want!"
string(54) ""Srting with a slash: \\ Just a slash is that I want!""
string(51) "Srting with a slash: \ Just a slash is that I want!"
string(54) ""Srting with a slash: \\ Just a slash is that I want!""
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77623&edit=1