Skip to content

Commit 479922f

Browse files
committed
resolve decode issue
1 parent f248c8c commit 479922f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 3.0.2 - 2025-08-14
4+
- Auto-resolve functionality of `associative: true` was used on decoding
5+
36
## 3.0.1 - 2025-08-13
47
- Allow already decoded values to be used
58

src/Rules/BaseRule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
3636

3737
if ($this->decode) {
3838
$value = json_decode($value, flags: JSON_THROW_ON_ERROR);
39+
} elseif (is_array($value) && ! array_is_list($value)) {
40+
// If the original json was decoded with `associative: true` the validator will not work correctly, so re-encode and decode it in such a case
41+
$value = json_decode(json_encode($value, flags: JSON_THROW_ON_ERROR), flags: JSON_THROW_ON_ERROR);
3942
}
4043

4144
$result = $this->schemaValidator->validate($this->determineSchemaName(), $value);

0 commit comments

Comments
 (0)