Blank line inside empty array/object when JSON_PRETTY_PRINT is set
| Bug #66021 | Blank line inside empty array/object when JSON_PRETTY_PRINT is set | ||||
|---|---|---|---|---|---|
| Submitted: | 2013-11-02 18:27 UTC | Modified: | - | ||
| From: | pleasestand at live dot com | Assigned: | |||
| Status: | Closed | Package: | JSON related | ||
| PHP Version: | master-Git-2013-11-02 (Git) | OS: | |||
| Private report: | No | CVE-ID: | None | ||
[2013-11-02 18:27 UTC] pleasestand at live dot com
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:
--------------
[
[
],
{
}
]
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2014-04-14 01:56 UTC] stas@php.net
-Status: Open +Status: Closed