Skip to content

Commit b62fea7

Browse files
authored
fix: property is passed as integer and cannot be accessed (#784)
1 parent a94f60c commit b62fea7

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Create deep copy before checking each sub schema in anyOf ([#792](https://github.com/jsonrainbow/json-schema/pull/792))
1717
- Correctly set the schema ID when passing it as assoc array ([#794](https://github.com/jsonrainbow/json-schema/pull/794))
1818
- Create deep copy before checking each sub schema in oneOf when only check_mode_apply_defaults is set ([#795](https://github.com/jsonrainbow/json-schema/pull/795))
19+
- Additional property casted into int when actually is numeric string ([#784](https://github.com/jsonrainbow/json-schema/pull/784))
1920

2021
### Changed
2122
- Used PHPStan's int-mask-of<T> type where applicable ([#779](https://github.com/jsonrainbow/json-schema/pull/779))

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ public function getValidTests(): array
189189
"additionalProperties": true
190190
}'
191191
],
192+
'additional property casted into int when actually is numeric string (#784)' => [
193+
'{
194+
"prop1": {
195+
"123": "a"
196+
}
197+
}',
198+
'{
199+
"type": "object",
200+
"additionalProperties": {
201+
"type": "object",
202+
"properties": {
203+
"123": {
204+
"type": "string"
205+
}
206+
}
207+
}
208+
}'
209+
],
192210
];
193211
}
194212
}

0 commit comments

Comments
 (0)