1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Add a bit more accuracy

This commit is contained in:
Brown 2020-06-25 01:00:11 -04:00
parent e26922010a
commit b8ebed0b85
2 changed files with 31 additions and 1 deletions

View File

@ -245,11 +245,16 @@ class Taint
$fetch_nesting--;
}
if ($previous_path_type === 'array-fetch') {
if (substr($previous_path_type, 0, 11) === 'array-fetch') {
$fetch_nesting++;
}
if (strpos($previous_path_type, 'array-assignment-') === 0) {
if ($fetch_nesting > 0) {
$fetch_nesting--;
continue;
}
if (substr($previous_path_type, 17) === substr($path_type, 12)) {
break;
}

View File

@ -427,6 +427,13 @@ class TaintTest extends TestCase
echo $m["b"];
}'
],
'taintFreeNestedArrayWithOffsetAccessedExplicitly' => [
'<?php
$a = [];
$a[] = ["a" => $_GET["name"], "b" => "foo"];
echo $a[0]["b"];',
],
];
}
@ -1267,6 +1274,24 @@ class TaintTest extends TestCase
echo $m->taint;',
'error_message' => 'TaintedInput',
],
'taintNestedArrayWithOffsetAccessedInForeach' => [
'<?php
$a = [];
$a[0] = ["a" => $_GET["name"], "b" => "foo"];
foreach ($a as $m) {
echo $m["a"];
}',
'error_message' => 'TaintedInput',
],
'taintNestedArrayWithOffsetAccessedExplicitly' => [
'<?php
$a = [];
$a[] = ["a" => $_GET["name"], "b" => "foo"];
echo $a[0]["a"];',
'error_message' => 'TaintedInput',
],
];
}
}