Skip to content

Commit 987b705

Browse files
authored
JSON format checking improved
#2080 (...) And I thought the correct code was (strpos($value, '"') === 0 && strrpos($value, '"') === strlen($value) - 1 ) (...)
1 parent cd97aba commit 987b705

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

system/Entity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,8 @@ private function castAsJson($value, bool $asArray = false)
588588
$tmp = ! is_null($value) ? ($asArray ? [] : new \stdClass) : null;
589589
if (function_exists('json_decode'))
590590
{
591-
if ((is_string($value) && (strpos($value, '[') === 0 || strpos($value, '{') === 0 || (strpos($value, '"') === 0 && strrpos($value, '"') === 0 ))) || is_numeric($value))
591+
$strlen = is_strimg($value) ? strlen($value) : 0;
592+
if (($strlen > 1 && is_string($value) && ((strpos($value, '[') === 0 && strrpos($value, ']') === $strlen - 1) || (strpos($value, '{') === 0 && strrpos($value, '}') === $strlen - 1) || (strpos($value, '"') === 0 && strrpos($value, '"') === $strlen - 1))) || is_numeric($value))
592593
{
593594
$tmp = json_decode($value, $asArray);
594595

0 commit comments

Comments
 (0)