Merge pull request #3213 from RasmusWL/python-iter-str-seq-with-tests

Python: supress non-useful results (w/ tests) for iter str/seq query
This commit is contained in:
Taus
2020-05-01 11:04:05 +02:00
committed by GitHub
2 changed files with 24 additions and 1 deletions

View File

@@ -12,6 +12,7 @@
*/
import python
import semmle.python.filters.Tests
predicate has_string_type(Value v) {
v.getClass() = ClassValue::str()
@@ -28,7 +29,10 @@ where
iter.pointsTo(seq, seq_origin) and
has_string_type(str) and
seq.getClass().isIterable() and
not has_string_type(seq)
not has_string_type(seq) and
// suppress occurrences from tests
not seq_origin.getScope().getScope*() instanceof TestScope and
not str_origin.getScope().getScope*() instanceof TestScope
select loop,
"Iteration over $@, of class " + seq.getClass().getName() + ", may also iterate over $@.",
seq_origin, "sequence", str_origin, "string"