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

Fix crash newly introduced

This commit is contained in:
Brown 2020-05-11 09:34:07 -04:00
parent 813302206a
commit 3554aa4435
2 changed files with 35 additions and 0 deletions

View File

@ -319,6 +319,7 @@ class LoopAnalyzer
foreach ($pre_loop_context->vars_in_scope as $var_id => $_) {
if (!isset($pre_condition_vars_in_scope[$var_id])
&& isset($inner_context->vars_in_scope[$var_id])
&& \strpos($var_id, '->') === false
&& \strpos($var_id, '[') === false
) {

View File

@ -408,6 +408,40 @@ class WhileTest extends \Psalm\Tests\TestCase
return rand(0, 1) ? $s : null;
}'
],
'thornyLoop' => [
'<?php
function searchCode(string $content, array &$tmp) : void {
// separer les balises du texte
$tmp = [];
$reg = \'/(<[^>]+>)|([^<]+)+/isU\';
// pour chaque element trouve :
$str = "";
$offset = 0;
while (preg_match($reg, $content, $parse, PREG_OFFSET_CAPTURE, $offset)) {
// si une balise a ete detectee
if($parse[1][0]) {
// sauvegarde du texte precedent si il existe
if($str !== "") {
$tmp[] = ["txt", $str];
}
// sauvegarde de la balise
$tmp[] = ["code", trim($parse[1][0])];
// initialisation du texte suivant
$str = "";
} else {
// ajout du texte a la fin de celui qui est deja detecte
$str .= $parse[2][0];
}
// Update offset to the end of the match
$offset = $parse[0][1] + strlen($parse[0][0]);
unset($parse);
}
}'
],
];
}