Skip to content

Commit

Permalink
Merge pull request #336 from Wixel/fix-328
Browse files Browse the repository at this point in the history
Fixes #328
  • Loading branch information
filisko authored Jul 15, 2022
2 parents 03050d9 + 8a69490 commit 8de017f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions gump.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1887,11 +1887,9 @@ protected function validate_regex($field, array $input, array $params = [], $val
*/
protected function validate_valid_json_string($field, array $input, array $params = [], $value = null)
{
if (!is_string($input[$field]) || !is_object(json_decode($value))) {
return false;
}

return true;
return is_string($input[$field])
&& is_array(json_decode($value, true))
&& (json_last_error() == JSON_ERROR_NONE);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/Validators/ValidJsonStringValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function successProvider()
return [
['{}'],
['{"testing": true}'],
['["one", "two"]'],
];
}

Expand All @@ -52,4 +53,4 @@ public function testWhenInputIsEmptyAndNotRequiredIsSuccess()
{
$this->assertTrue($this->validate(self::RULE, ''));
}
}
}

0 comments on commit 8de017f

Please sign in to comment.