Skip to content

Commit 2465fe4

Browse files
committed
Merge pull request #132 from loucho/patch-1
Make the enum element comparison strict
2 parents 680d026 + 14443c5 commit 2465fe4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/JsonSchema/Constraints/EnumConstraint.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,24 @@ class EnumConstraint extends Constraint
2323
public function check($element, $schema = null, $path = null, $i = null)
2424
{
2525
// Only validate enum if the attribute exists
26-
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
26+
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
2727
return;
2828
}
2929

3030
foreach ($schema->enum as $enum) {
31-
if ((gettype($element) === gettype($enum)) && ($element == $enum)) {
32-
return;
31+
$type = gettype($element);
32+
if ($type === gettype($enum)) {
33+
if ($type == "object") {
34+
if ($element == $enum)
35+
return;
36+
} else {
37+
if ($element === $enum)
38+
return;
39+
40+
}
3341
}
3442
}
3543

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

0 commit comments

Comments
 (0)