Skip to content

Commit 18636f0

Browse files
committed
fix: additional property casted into int when actually is numeric string
1 parent 7660882 commit 18636f0

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/JsonSchema/Constraints/ObjectConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected function &getProperty(&$element, $property, $fallback = null)
159159
{
160160
if (is_array($element) && (isset($element[$property]) || array_key_exists($property, $element)) /*$this->checkMode == self::CHECK_MODE_TYPE_CAST*/) {
161161
return $element[$property];
162-
} elseif (is_object($element) && property_exists($element, $property)) {
162+
} elseif (is_object($element) && property_exists($element, (string) $property)) {
163163
return $element->$property;
164164
}
165165

tests/Constraints/AdditionalPropertiesTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,42 @@ public function getValidTests(): array
189189
"additionalProperties": true
190190
}'
191191
],
192+
[
193+
'{
194+
"prop1": {
195+
"prop2": "a"
196+
}
197+
}',
198+
'{
199+
"type": "object",
200+
"additionalProperties": {
201+
"type": "object",
202+
"properties": {
203+
"prop2": {
204+
"type": "string"
205+
}
206+
}
207+
}
208+
}'
209+
],
210+
[
211+
'{
212+
"prop1": {
213+
"123": "a"
214+
}
215+
}',
216+
'{
217+
"type": "object",
218+
"additionalProperties": {
219+
"type": "object",
220+
"properties": {
221+
"123": {
222+
"type": "string"
223+
}
224+
}
225+
}
226+
}'
227+
],
192228
];
193229
}
194230
}

0 commit comments

Comments
 (0)