Skip to content

Commit

Permalink
JSON format checking improved
Browse files Browse the repository at this point in the history
codeigniter4#2080 
(...) And I thought the correct code was (strpos($value, '"') === 0 && strrpos($value, '"') === strlen($value) - 1 ) (...)
  • Loading branch information
nowackipawel authored Jun 29, 2019
1 parent cd97aba commit 987b705
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion system/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ private function castAsJson($value, bool $asArray = false)
$tmp = ! is_null($value) ? ($asArray ? [] : new \stdClass) : null;
if (function_exists('json_decode'))
{
if ((is_string($value) && (strpos($value, '[') === 0 || strpos($value, '{') === 0 || (strpos($value, '"') === 0 && strrpos($value, '"') === 0 ))) || is_numeric($value))
$strlen = is_strimg($value) ? strlen($value) : 0;
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))
{
$tmp = json_decode($value, $asArray);

Expand Down

0 comments on commit 987b705

Please sign in to comment.