Skip to content

Commit 3c13a1b

Browse files
committed
bug #798 [Live] Fix checksum calculation for deeply nested data (1ed)
This PR was merged into the 2.x branch. Discussion ---------- [Live] Fix checksum calculation for deeply nested data | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | - | License | MIT For a consistent checksum we need to sort the whole input. Commits ------- 5b0b862 [Live] Fix checksum calculation for deeply nested data
2 parents eb7023a + 5b0b862 commit 3c13a1b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/LiveComponent/src/LiveComponentHydrator.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private static function coerceStringValue(string $value, string $type, bool $all
243243
private function calculateChecksum(array $dehydratedPropsData): ?string
244244
{
245245
// sort so it is always consistent (frontend could have re-ordered data)
246-
ksort($dehydratedPropsData);
246+
$this->recursiveKeySort($dehydratedPropsData);
247247

248248
return base64_encode(hash_hmac('sha256', json_encode($dehydratedPropsData), $this->secret, true));
249249
}
@@ -549,4 +549,14 @@ private function combineAndValidateProps(array $props, array $updatedPropsFromPa
549549

550550
return $dehydratedOriginalProps;
551551
}
552+
553+
private function recursiveKeySort(array &$data): void
554+
{
555+
foreach ($data as &$value) {
556+
if (\is_array($value)) {
557+
$this->recursiveKeySort($value);
558+
}
559+
}
560+
ksort($data);
561+
}
552562
}

0 commit comments

Comments
 (0)