Skip to content

Commit ea7f048

Browse files
committed
fix(ast): Bug with String interpolation and values
1 parent 045bfc9 commit ea7f048

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

ql/lib/codeql/bicep/ast/Literals.qll

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,34 @@ class Number extends Literals instanceof NumberImpl {
6666
int getValue() { result = NumberImpl.super.getValue().toInt() }
6767
}
6868

69+
class String = StringLiteral;
70+
6971
/**
7072
* A String literal in the AST.
7173
*/
7274
class StringLiteral extends Literals instanceof StringImpl {
75+
/**
76+
* Gets the value of the string literal.
77+
*/
7378
string getValue() {
74-
exists(StringContentLiteral content |
75-
content = this.getAChild() and
76-
result = content.getValue()
79+
result = concat(int index, string output |
80+
exists(StringContentLiteral content |
81+
content = StringImpl.super.getChild(index) and
82+
output = content.getValue()
83+
)
84+
or
85+
exists(Interpolation interpolation |
86+
interpolation = StringImpl.super.getChild(index) and
87+
output = interpolation.getValue()
88+
)
89+
|
90+
output order by index
7791
)
7892
}
93+
94+
Interpolation getInterpolation(int index) {
95+
result = StringImpl.super.getChild(index)
96+
}
7997
}
8098

8199
/**

ql/lib/codeql/bicep/ast/internal/Interpolation.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ class InterpolationImpl extends TInterpolation, ExprImpl {
2121

2222
override string toString() { result = ast.toString() }
2323

24+
ExprImpl getExpression() {
25+
toTreeSitter(result) = ast.getChild()
26+
}
2427
}

ql/lib/codeql/bicep/ast/internal/String.qll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*
44
* WARNING: this file is generated, do not edit manually
55
*/
6+
67
private import AstNodes
78
private import TreeSitter
89
private import codeql.bicep.ast.AstNodes
910
private import Literals
1011

11-
1212
/**
1313
* A String AST Node.
1414
*/
@@ -20,13 +20,15 @@ class StringImpl extends TString, LiteralsImpl {
2020
StringImpl() { this = TString(ast) }
2121

2222
override string toString() { result = ast.toString() }
23+
2324
/**
2425
* Get the literal value
25-
*
26+
*
2627
* TODO: This is broken.
2728
*/
2829
override string getValue() { result = ast.getChild(_).toString() }
2930

30-
31-
32-
}
31+
AstNode getChild(int index) {
32+
toTreeSitter(result) = ast.getChild(index)
33+
}
34+
}

0 commit comments

Comments
 (0)