Skip to content

Commit 33c1731

Browse files
committed
Add test for not extracting values for intermediate string concatenations
1 parent da8cc13 commit 33c1731

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
| tst.go:4:6:4:8 | "a" | a |
2+
| tst.go:4:6:4:14 | ...+... | <no string value stored> |
3+
| tst.go:4:6:4:20 | ...+... | <no string value stored> |
4+
| tst.go:4:6:4:26 | ...+... | <no string value stored> |
5+
| tst.go:4:6:4:32 | ...+... | <no string value stored> |
6+
| tst.go:4:6:4:38 | ...+... | abcdef |
7+
| tst.go:4:12:4:14 | "b" | b |
8+
| tst.go:4:18:4:20 | "c" | c |
9+
| tst.go:4:24:4:26 | "d" | d |
10+
| tst.go:4:30:4:32 | "e" | e |
11+
| tst.go:4:36:4:38 | "f" | f |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package main
2+
3+
func main() {
4+
_ = "a" + "b" + "c" + "d" + "e" + "f"
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import go
2+
3+
string checkStringValue(Expr e) {
4+
result = e.getStringValue()
5+
or
6+
not exists(e.getStringValue()) and result = "<no string value stored>"
7+
}
8+
9+
from Expr e
10+
where e.getType() instanceof StringType
11+
// We should get string values for `"a"`, `"b"`, `"c"` and `"a" + "b" + "c"
12+
// but not `"a" + "b"`. In the extractor we avoid storing the value of
13+
// intermediate strings in string concatenations because in pathological cases
14+
// this could lead to a quadratic blowup in the size of string values stored,
15+
// which then causes performance problems when we iterate through all string
16+
// values.
17+
select e, checkStringValue(e)

0 commit comments

Comments
 (0)