Skip to content

Commit

Permalink
Validate callback type (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
abienvenu authored Jan 30, 2022
1 parent 4e9c366 commit 738c36e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/JsonpCallbackValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class JsonpCallbackValidator
*/
public static function validate($callback)
{
if (!is_string($callback)) {
return false;
}

foreach (explode('.', $callback) as $identifier) {
if (!preg_match(self::$regexp, $identifier)) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions tests/JsonpCallbackValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public static function dataProviderForTestValidate()
array("array_of_functions['k'ey'']", self::IS_INVALID),
array("array_of_functions[''']", self::IS_INVALID),
array("array_of_functions['\'']", self::IS_VALID),
array([], self::IS_INVALID),
array(new \stdClass(), self::IS_INVALID),
);
}

Expand Down

0 comments on commit 738c36e

Please sign in to comment.