Skip to content

Commit 775a4f5

Browse files
authored
Merge pull request #567 from erayd/bugfix-566-not
Don't run checks which assume a defined instance against undefined
2 parents 6562463 + 02ab55c commit 775a4f5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
153153
$propertyName = end($propertyPaths);
154154
$this->addError(ConstraintError::REQUIRED(), $path, array('property' => $propertyName));
155155
}
156+
} else {
157+
// if the value is both undefined and not required, skip remaining checks
158+
// in this method which assume an actual, defined instance when validating.
159+
if ($value instanceof self) {
160+
return;
161+
}
156162
}
157163
}
158164

tests/Constraints/NotTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ public function getInvalidTests()
3131
}
3232
}
3333
}'
34+
),
35+
array( // check that a missing, required property is correctly validated
36+
'{"y": "foo"}',
37+
'{
38+
"type": "object",
39+
"required": ["x"],
40+
"properties": {
41+
"x": {
42+
"not": {
43+
"type": "null"
44+
}
45+
}
46+
}
47+
}'
3448
)
3549
);
3650
}
@@ -69,6 +83,19 @@ public function getValidTests()
6983
}
7084
}
7185
}'
86+
),
87+
array( // check that a missing, non-required property isn't validated
88+
'{"y": "foo"}',
89+
'{
90+
"type": "object",
91+
"properties": {
92+
"x": {
93+
"not": {
94+
"type": "null"
95+
}
96+
}
97+
}
98+
}'
7299
)
73100
);
74101
}

0 commit comments

Comments
 (0)