Skip to content

Commit

Permalink
fix: additional property casted into int when actually is numeric string
Browse files Browse the repository at this point in the history
  • Loading branch information
aistis- committed Feb 11, 2025
1 parent 7660882 commit 18636f0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/ObjectConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected function &getProperty(&$element, $property, $fallback = null)
{
if (is_array($element) && (isset($element[$property]) || array_key_exists($property, $element)) /*$this->checkMode == self::CHECK_MODE_TYPE_CAST*/) {
return $element[$property];
} elseif (is_object($element) && property_exists($element, $property)) {
} elseif (is_object($element) && property_exists($element, (string) $property)) {
return $element->$property;
}

Expand Down
36 changes: 36 additions & 0 deletions tests/Constraints/AdditionalPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,42 @@ public function getValidTests(): array
"additionalProperties": true
}'
],
[
'{
"prop1": {
"prop2": "a"
}
}',
'{
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"prop2": {
"type": "string"
}
}
}
}'
],
[
'{
"prop1": {
"123": "a"
}
}',
'{
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"123": {
"type": "string"
}
}
}
}'
],
];
}
}

0 comments on commit 18636f0

Please sign in to comment.