Skip to content

Commit bafe7e6

Browse files
committed
JS: Fix template literal detection in string concatination
1 parent 861e4ee commit bafe7e6

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

javascript/ql/src/LanguageFeatures/TemplateSyntaxInStringLiteral.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ class CandidateStringLiteral extends StringLiteral {
7676
* ```
7777
*/
7878
predicate hasObjectProvidingTemplateVariables(CandidateStringLiteral lit) {
79-
exists(DataFlow::CallNode call, DataFlow::ObjectLiteralNode obj |
80-
call.getAnArgument().getALocalSource() = obj and
81-
call.getAnArgument().asExpr() = lit and
79+
exists(DataFlow::CallNode call, DataFlow::ObjectLiteralNode obj, DataFlow::Node stringArg |
80+
stringArg = [StringConcatenation::getRoot(lit.flow()), lit.flow()] and
81+
stringArg = call.getAnArgument() and
82+
obj.flowsTo(call.getAnArgument()) and
8283
forex(string name | name = lit.getAReferencedVariable() | exists(obj.getAPropertyWrite(name)))
8384
)
8485
}

javascript/ql/test/query-tests/LanguageFeatures/TemplateSyntaxInStringLiteral/TemplateSyntaxInStringLiteral.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@
33
| TemplateSyntaxInStringLiteral.js:19:11:19:36 | 'global ... alVar}' | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:14:5:14:13 | globalVar | globalVar |
44
| TemplateSyntaxInStringLiteral.js:28:15:28:21 | "${x} " | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:25:14:25:14 | x | x |
55
| TemplateSyntaxInStringLiteral.js:42:17:42:57 | "Name: ... oobar}" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:37:11:37:16 | foobar | foobar |
6-
| TemplateSyntaxInStringLiteral.js:47:27:47:51 | ") ${ex ... got (" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:45:20:45:27 | expected | expected |
7-
| TemplateSyntaxInStringLiteral.js:47:71:47:83 | ") ${actual}" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:45:12:45:17 | actual | actual |
86
| TemplateSyntaxInStringLiteral.js:62:15:62:29 | "Name: ${name}" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:61:30:61:33 | name | name |
97
| TemplateSyntaxInStringLiteral.js:66:11:66:44 | "Name: ... {name}" | This string is not a template literal, but appears to reference the variable $@. | TemplateSyntaxInStringLiteral.js:61:30:61:33 | name | name |

javascript/ql/test/query-tests/LanguageFeatures/TemplateSyntaxInStringLiteral/TemplateSyntaxInStringLiteral.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function foo1() {
4444

4545
function a(actual, expected, description) {
4646
assert(false, "a", description, "expected (" +
47-
typeof expected + ") ${expected} but got (" + typeof actual + ") ${actual}", { // $SPURIOUS:Alert
47+
typeof expected + ") ${expected} but got (" + typeof actual + ") ${actual}", {
4848
expected: expected,
4949
actual: actual
5050
});

0 commit comments

Comments
 (0)