From d82e1b9f2b9b1659b2bbb920b454783dbeabebf8 Mon Sep 17 00:00:00 2001 From: Aistis Date: Wed, 12 Feb 2025 00:12:59 +0200 Subject: [PATCH 1/3] fix: additional property casted into int when actually is numeric string --- .../Constraints/ObjectConstraint.php | 2 +- .../Constraints/AdditionalPropertiesTest.php | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/JsonSchema/Constraints/ObjectConstraint.php b/src/JsonSchema/Constraints/ObjectConstraint.php index 011e600c..0752ac13 100644 --- a/src/JsonSchema/Constraints/ObjectConstraint.php +++ b/src/JsonSchema/Constraints/ObjectConstraint.php @@ -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; } diff --git a/tests/Constraints/AdditionalPropertiesTest.php b/tests/Constraints/AdditionalPropertiesTest.php index 82b31971..78fe31bc 100644 --- a/tests/Constraints/AdditionalPropertiesTest.php +++ b/tests/Constraints/AdditionalPropertiesTest.php @@ -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" + } + } + } + }' + ], ]; } } From 6464f87b228c797046b2ba12de6549ef48c9a825 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 26 Feb 2025 19:45:51 +0100 Subject: [PATCH 2/3] docs: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53a92fc2..e169991b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Create deep copy before checking each sub schema in anyOf ([#792](https://github.com/jsonrainbow/json-schema/pull/792)) - Correctly set the schema ID when passing it as assoc array ([#794](https://github.com/jsonrainbow/json-schema/pull/794)) - 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)) +- Additional property casted into int when actually is numeric string ([#784](https://github.com/jsonrainbow/json-schema/pull/784)) ### Changed - Used PHPStan's int-mask-of type where applicable ([#779](https://github.com/jsonrainbow/json-schema/pull/779)) From 035a97942e4d9b58b756a97448e987abf72cb842 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Wed, 26 Feb 2025 19:56:11 +0100 Subject: [PATCH 3/3] refactor: remove redundant test case and cleanup remaining testcase --- .../Constraints/AdditionalPropertiesTest.php | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/tests/Constraints/AdditionalPropertiesTest.php b/tests/Constraints/AdditionalPropertiesTest.php index 78fe31bc..46b29a82 100644 --- a/tests/Constraints/AdditionalPropertiesTest.php +++ b/tests/Constraints/AdditionalPropertiesTest.php @@ -189,40 +189,22 @@ public function getValidTests(): array "additionalProperties": true }' ], - [ - '{ - "prop1": { - "prop2": "a" - } - }', + 'additional property casted into int when actually is numeric string (#784)' => [ '{ - "type": "object", - "additionalProperties": { - "type": "object", - "properties": { - "prop2": { - "type": "string" - } + "prop1": { + "123": "a" } - } - }' - ], - [ - '{ - "prop1": { - "123": "a" - } }', '{ - "type": "object", - "additionalProperties": { "type": "object", - "properties": { - "123": { - "type": "string" - } + "additionalProperties": { + "type": "object", + "properties": { + "123": { + "type": "string" + } + } } - } }' ], ];