Skip to content

Commit a919540

Browse files
committed
StringUtil::prettyJson() - simply decode as array... no need to attempt to decode as obj
1 parent 7b0fd82 commit a919540

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

src/Debug/Utility/StringUtil.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,7 @@ public static function prettyJson($json, $encodeFlags = 0, $encodeFlagsAdd = JSO
311311
// json doesn't appear to contain encoded unicode
312312
$flags |= JSON_UNESCAPED_UNICODE;
313313
}
314-
// attempt to decode as object first
315-
$decoded = \json_decode($json);
316-
// JSON_ERROR_INVALID_PROPERTY_NAME is php 7.0+ just check for error
317-
if (\json_last_error() !== JSON_ERROR_NONE) {
318-
$decoded = \json_decode($json, true);
319-
}
314+
$decoded = \json_decode($json, true);
320315
return \json_last_error() === JSON_ERROR_NONE
321316
? \json_encode($decoded, $flags)
322317
: false;

tests/Debug/Type/StringEncodedTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ public static function providerTestMethod()
340340
$jsonPrettified = Debug::getInstance()->stringUtil->prettyJson($json);
341341
self::assertSame(\strlen($jsonPrettified), $entry['args'][0]['strlen']);
342342
$expect = \substr($jsonPrettified, 0, 123);
343-
self::assertSame($expect, $entry['args'][0]['value']);
343+
$actual = $entry['args'][0]['value'];
344+
self::assertSame($expect, $actual);
344345
},
345346
'html' => static function ($html) {
346347
$json = \file_get_contents(TEST_DIR . '/../composer.json');

0 commit comments

Comments
 (0)