Skip to content

Commit 03968ba

Browse files
committed
Fix breaking bugfix for validation rules (array of objects) in newer Laravel versions
1 parent 2c2656f commit 03968ba

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Extracting/ParsesValidationRules.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ public function getParametersFromValidationRules(array $validationRulesByParamet
141141
}
142142

143143
/**
144-
* Transform validation rules from:
144+
* Transform validation rules:
145+
* 1. from strings to arrays:
145146
* 'param1' => 'int|required' TO 'param1' => ['int', 'required']
147+
* 2. from '*.foo' to '
146148
*
147149
* @param array<string,string|string[]> $rules
148150
*
@@ -169,7 +171,10 @@ protected function normaliseRules(array $rules): array
169171
return collect($newRules)->mapWithKeys(function ($val, $paramName) use ($rules) {
170172
// Transform the key names back from '__asterisk__' to '*'
171173
if (Str::contains($paramName, '__asterisk__')) {
172-
$paramName = str_replace('__asterisk__', '*', $paramName);
174+
// In Laravel < v11.44, * keys were replaced with only "__asterisk__"
175+
// After that, * keys were replaced with "__asterisk__<random placeholder>", eg "__asterisk__dkjiu78gujjhb
176+
// See https://github.com/laravel/framework/pull/54845/
177+
$paramName = preg_replace('/__asterisk__[^.]*\b/', '*', $paramName);
173178
}
174179

175180
// Transform the key names back from 'ids.0' to 'ids.*'

tests/Unit/ValidationRuleParsingTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function can_parse_rule_objects()
8181
);
8282
}
8383

84-
8584
/** @test */
8685
public function can_transform_arrays_and_objects()
8786
{

0 commit comments

Comments
 (0)