Skip to content

Commit 070233c

Browse files
carlbennettclaude
andcommitted
Fix StringProcessor and HttpCode bugs exposed by tests
StringProcessor: - fuzzyMatch: use lambda in preg_replace_callback instead of passing 'preg_quote' directly, which broke in PHP 8 strict typing - sanitizeForUrl: replace array_walk/trim with lambda to avoid passing a third argument that trim does not accept HttpCode: - codeFromString: include underscore in allowed character class so that inputs like 'NOT_FOUND' and 'ACCESS_DENIED' are handled correctly, consistent with space-separated equivalents Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2d085f3 commit 070233c

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/Libraries/Core/HttpCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static function codeFromInt(int $value): string
128128

129129
public static function codeFromString(string $value): int
130130
{
131-
$needle = \str_replace(' ', '_', \strtoupper(\preg_replace('/[^A-Za-z\s]/', '', \trim($value))));
131+
$needle = \str_replace(' ', '_', \strtoupper(\preg_replace('/[^A-Za-z\s_]/', '', \trim($value))));
132132
if (\substr($needle, 0, 5) == 'HTTP_') $needle = \substr($needle, 5);
133133

134134
switch ($needle)

src/Libraries/Core/StringProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class StringProcessor
1313
*/
1414
public static function fuzzyMatch(string $pattern, string $subject): bool
1515
{
16-
$pattern = \preg_replace_callback('/([^*])/', 'preg_quote', $pattern);
16+
$pattern = \preg_replace_callback('/([^*])/', fn($m) => \preg_quote($m[0]), $pattern);
1717
$pattern = \str_replace('*', '.*', $pattern);
1818
return (bool) \preg_match('/^' . $pattern . '$/i', $subject);
1919
}
@@ -41,7 +41,7 @@ public static function sanitizeForUrl(array|string $haystack, bool $lowercase =
4141
}
4242
else
4343
{
44-
\array_walk($result, '\trim', '-');
44+
\array_walk($result, fn(&$v) => $v = \trim($v, '-'));
4545
}
4646
if ($lowercase) $result = \strtolower($result);
4747
return $result;

0 commit comments

Comments
 (0)