1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Merge pull request #10489 from iMu3ic/fix_pattern_length_check

Fix Uncaught RuntimeException: PHP Error: Uninitialized string offset 0 when $pattern is empty
This commit is contained in:
orklah 2023-12-14 19:34:04 +01:00 committed by GitHub
commit 64dc2ff747
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,6 +51,7 @@ use function strlen;
use function strpos;
use function strtolower;
use function substr;
use function trim;
/**
* @internal
@ -636,17 +637,19 @@ final class FunctionCallReturnTypeFetcher
$first_arg_value = $first_stmt_type->getSingleStringLiteral()->value;
$pattern = substr($first_arg_value, 1, -1);
if (strlen(trim($pattern)) > 0) {
$pattern = trim($pattern);
if ($pattern[0] === '['
&& $pattern[1] === '^'
&& substr($pattern, -1) === ']'
) {
$pattern = substr($pattern, 2, -1);
if ($pattern[0] === '['
&& $pattern[1] === '^'
&& substr($pattern, -1) === ']'
) {
$pattern = substr($pattern, 2, -1);
if (self::simpleExclusion($pattern, $first_arg_value[0])) {
$removed_taints[] = 'html';
$removed_taints[] = 'has_quotes';
$removed_taints[] = 'sql';
if (self::simpleExclusion($pattern, $first_arg_value[0])) {
$removed_taints[] = 'html';
$removed_taints[] = 'has_quotes';
$removed_taints[] = 'sql';
}
}
}
}