Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7b803a

Browse files
committed
Python: Fix modernisation of py/iteration-string-and-sequence
Introduced a regression, since the old code was: ``` predicate is_a_string_type(ClassObject seqtype) { seqtype = theBytesType() and major_version() = 2 or seqtype = theUnicodeType() } ``` but *now* we're good!
1 parent 0509228 commit d7b803a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

python/ql/src/Statements/IterableStringOrSequence.ql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313

1414
import python
1515

16+
predicate has_string_type(Value v) {
17+
v.getClass() = ClassValue::bytes() and major_version() = 2
18+
or
19+
v.getClass() = ClassValue::unicode()
20+
}
1621

1722
from
1823
For loop, ControlFlowNode iter, Value str, Value seq, ControlFlowNode seq_origin, ControlFlowNode str_origin
1924
where
2025
loop.getIter().getAFlowNode() = iter and
2126
iter.pointsTo(str, str_origin) and
2227
iter.pointsTo(seq, seq_origin) and
23-
str.getClass() = ClassValue::str() and
28+
has_string_type(str) and
2429
seq.getClass().isIterable() and
25-
not seq.getClass() = ClassValue::str()
30+
not has_string_type(seq)
2631
select loop, "Iteration over $@, of class " + seq.getClass().getName() + ", may also iterate over $@.",
2732
seq_origin, "sequence", str_origin, "string"

0 commit comments

Comments
 (0)