Skip to content

Commit

Permalink
Merge pull request #10470 from creative-commoners/pulls/4.11/case-ins…
Browse files Browse the repository at this point in the history
…ensitive-casting

FIX Normalise casing before casting fields
  • Loading branch information
GuySartorelli committed Sep 8, 2022
2 parents a7c8ce8 + 6d885ab commit 7e9ced0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/View/ViewableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,12 @@ public function setCustomisedObj(ViewableData $object)
*/
public function castingHelper($field)
{
$specs = static::config()->get('casting');
if (isset($specs[$field])) {
return $specs[$field];
// Get casting if it has been configured.
// DB fields and PHP methods are all case insensitive so we normalise casing before checking.
$specs = array_change_key_case(static::config()->get('casting'), CASE_LOWER);
$fieldLower = strtolower($field);
if (isset($specs[$fieldLower])) {
return $specs[$fieldLower];
}

// If no specific cast is declared, fall back to failover.
Expand Down

0 comments on commit 7e9ced0

Please sign in to comment.