Skip to content

Commit d9af62c

Browse files
committed
unified: Handle string segments in Expr.getStringValue()
1 parent 277a282 commit d9af62c

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

unified/ql/lib/codeql/unified/internal/FacadeAst.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ module Unified {
5353
string getStringValue() {
5454
// TODO: we'll want to cook the string literals extractor-side, but for now
5555
// just strip the quotes here and ignore escape sequences.
56-
result = this.(StringLiteral).getValue().regexpCapture("\"(.*)\"", 1)
56+
exists(string text | text = this.(StringLiteral).getValue() |
57+
result = text.regexpCapture("\"(.*)\"", 1)
58+
or
59+
// Constant-segments of string interpolations are represented as string literals, but their raw text does not have quotes
60+
not exists(text.regexpCapture("\"(.*)\"", 1)) and
61+
result = text
62+
)
5763
}
5864

5965
/** Gets the immediately-enclosing expression, skipping over intermediate sub-nodes like `Argument`, and without crossing a function boundary. */

unified/ql/test/library-tests/BasicTest/test.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,9 @@ rawStringValue
165165
| strings.swift:4:27:4:32 | world | world |
166166
exprStringValue
167167
| strings.swift:1:10:1:16 | "hello" | hello |
168+
| strings.swift:2:11:2:16 | hello | hello |
169+
| strings.swift:2:23:2:28 | world | world |
170+
| strings.swift:3:11:3:16 | hello | hello |
171+
| strings.swift:3:28:3:33 | world | world |
172+
| strings.swift:4:11:4:16 | hello | hello |
173+
| strings.swift:4:27:4:32 | world | world |

0 commit comments

Comments
 (0)