Bug #66021 [NEW]: Blank line inside empty array/object when JSON_PRETTY_PRINT is set
| From: | pleasestand at live dot com | Date: | Sat, 02 Nov 2013 18:27:11 +0000 |
| Subject: | Bug #66021 [NEW]: Blank line inside empty array/object when JSON_PRETTY_PRINT is set | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-182562@lists.php.net to get a copy of this message | ||
From: pleasestand at live dot com
Operating system:
PHP version: master-Git-2013-11-02 (Git)
Package: JSON related
Bug Type: Bug
Bug description:Blank line inside empty array/object when JSON_PRETTY_PRINT is set
Description:
------------
The JSON_PRETTY_PRINT option to json_encode() causes a blank line to be
inserted between the brackets or braces of an empty array or object.
This is not how one would write out JSON by hand. Furthermore, it is
inconsistent with JavaScript's JSON.stringify() and Python's
json.dumps().
I think this may be unintentional because there is no test that shows
the author of cb9c8233fc2d (r303425) had considered these cases (and
chose not to put the brackets/braces on the same line).
I will submit a GitHub pull request shortly to fix this.
Test script:
---------------
<?php
echo json_encode([[],(object)[]], JSON_PRETTY_PRINT), "\n";
Expected result:
----------------
[
[],
{}
]
Actual result:
--------------
[
[
],
{
}
]
--
Edit bug report at https://bugs.php.net/bug.php?id=66021&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66021&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66021&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66021&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66021&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66021&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66021&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66021&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66021&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66021&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66021&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66021&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66021&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66021&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66021&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66021&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66021&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66021&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66021&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66021&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66021&r=mysqlcfg