Commit 5b0aa9c
authored
[2.x] fix(nicknames): cast min/max settings to int before passing to Schema\Str (#4599)
* test(nicknames): reproduce TypeError when min/max settings are empty strings
UserResourceFields passes the raw settings value to Schema\Str::minLength(int)
and maxLength(int). Numeric strings ('3', '150') coerce silently under PHP's
default weak typing, but an empty string — the result of an admin clearing
the min or max field in the nicknames config and saving — triggers:
Str::maxLength(): Argument #1 ($length) must be of type int, string given
From then on every forum request 500s because UserResourceFields is
invoked during JSON:API resource resolution. Fresh installs are unaffected
because the Extend\Settings() int defaults bypass the DB path.
Test reproduces the exact production stack trace. Fix follows.
* fix(nicknames): handle non-int min/max length settings
Cast the persisted setting to int before handing it to Schema\Str's
minLength/maxLength, and only apply the constraint when the admin has
configured a positive value. An empty field saved from the admin panel
was otherwise stored as '' — triggering a TypeError in PHP's default
weak coercion — and, after the naive cast, coerced to 0, which made
maxLength(0) reject every nickname.
Reveals a gap in Schema\Str: the int-only signature offers no way to
"disable" a length constraint via the condition argument without a
guard at the call site. Keeping the guard local for this RC fix.1 parent a0803ab commit 5b0aa9c
2 files changed
Lines changed: 50 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
35 | 42 | | |
36 | 43 | | |
37 | 44 | | |
| |||
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
46 | | - | |
47 | | - | |
| 53 | + | |
| 54 | + | |
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| |||
Lines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
181 | 222 | | |
0 commit comments