Skip to content

Commit a177c2d

Browse files
loucholoucho
authored and
loucho
committed
Make the enum element comparison strict
The current check is matching numeric strings that are not equal ( like "604.1" == "604.10" because of PHP's == behavior that converts numeric strings to numbers and then performs a numeric comparison), even if type is checked before the comparison, the value should be identic
1 parent 680d026 commit a177c2d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/JsonSchema/Constraints/EnumConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public function check($element, $schema = null, $path = null, $i = null)
2828
}
2929

3030
foreach ($schema->enum as $enum) {
31-
if ((gettype($element) === gettype($enum)) && ($element == $enum)) {
31+
if ((gettype($element) === gettype($enum)) && ($element === $enum)) {
3232
return;
3333
}
3434
}
3535

3636
$this->addError($path, "does not have a value in the enumeration " . print_r($schema->enum, true));
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)