Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Check if an entity is a string when validating it against integer, nu…
…mber and boolean

is_numeric(), is_int() and is_bool() are not sufficient when checking the data type of an entity. E.g. "2" is not numerical in javascript but in PHP it is.
  • Loading branch information
slopjong committed Feb 18, 2013
commit 6ac4207956ca12c880de49b42018ec9f5cb89d3a
8 changes: 4 additions & 4 deletions src/Json/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@ protected function validateType($entity, $schema, $entityName)
}
break;
case 'integer':
if (is_int($entity)) {
if (!is_string($entity) && is_int($entity)) {
$this->checkTypeInteger($entity, $schema, $entityName);
$valid = true;
}
break;
case 'number':
if (is_numeric($entity)) {
if (!is_string($entity) && is_numeric($entity)) {
$this->checkTypeNumber($entity, $schema, $entityName);
$valid = true;
}
break;
case 'boolean':
if (is_bool($entity)) {
if (!is_string($entity) && is_bool($entity)) {
$this->checkTypeBoolean($entity, $schema, $entityName);
$valid = true;
}
Expand Down Expand Up @@ -756,4 +756,4 @@ protected function checkDivisibleBy($entity, $schema, $entityName)

return $this;
}
}
}