Skip to content

Commit 879cb7c

Browse files
authored
Merge pull request github#17864 from asgerf/js/vue-attribute-syntax
JS: Fix parsing of special Vue attributes
2 parents 7ddc8f0 + 6aef571 commit 879cb7c

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

javascript/extractor/src/com/semmle/js/extractor/HTMLExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ private boolean isAngularTemplateAttributeName(String name) {
184184
private static final Pattern ANGULAR_FOR_LOOP_DECL =
185185
Pattern.compile("^ *let +(\\w+) +of(?: +|(?!\\w))(.*)");
186186

187+
/** Attribute names that look valid in HTML or in one of the template languages we support, like Vue and Angular. */
187188
private static final Pattern VALID_ATTRIBUTE_NAME =
188-
Pattern.compile("\\*?\\[?\\(?[\\w:_\\-]+\\]?\\)?");
189+
Pattern.compile("[*:@]?\\[?\\(?[\\w:_\\-.]+\\]?\\)?");
189190

190191
/** List of HTML attributes whose value is interpreted as JavaScript. */
191192
private static final Pattern JS_ATTRIBUTE =

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class Main {
4141
* A version identifier that should be updated every time the extractor changes in such a way that
4242
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4343
*/
44-
public static final String EXTRACTOR_VERSION = "2024-04-17";
44+
public static final String EXTRACTOR_VERSION = "2024-10-29";
4545

4646
public static final Pattern NEWLINE = Pattern.compile("\n");
4747

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<Blah :colonProp="x" @atProp="x" />
3+
<Blah :colonField.field="x" />
4+
</template>
5+
<script></script>

javascript/ql/test/library-tests/frameworks/Vue/tests.expected

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ component
7676
| single-file-component-3.vue:0:0:0:0 | single-file-component-3.vue |
7777
| single-file-component-4.vue:0:0:0:0 | single-file-component-4.vue |
7878
| single-file-component-5.vue:0:0:0:0 | single-file-component-5.vue |
79+
| special-syntax.vue:0:0:0:0 | special-syntax.vue |
7980
| tst.js:3:1:10:2 | new Vue ... 2\\n\\t}\\n}) |
8081
| tst.js:12:1:16:2 | new Vue ... \\t}),\\n}) |
8182
| tst.js:18:1:27:2 | Vue.com ... }\\n\\t}\\n}) |
@@ -126,6 +127,10 @@ templateElement
126127
| single-file-component-5.vue:2:5:18:9 | <p>...</> |
127128
| single-file-component-5.vue:4:1:16:9 | <script>...</> |
128129
| single-file-component-5.vue:17:1:18:8 | <style>...</> |
130+
| special-syntax.vue:1:1:4:11 | <template>...</> |
131+
| special-syntax.vue:2:3:2:37 | <blah>...</> |
132+
| special-syntax.vue:3:3:3:32 | <blah>...</> |
133+
| special-syntax.vue:5:1:5:17 | <script>...</> |
129134
xssSink
130135
| compont-with-route.vue:2:8:2:21 | v-html=dataA |
131136
| single-component-file-1.vue:2:8:2:21 | v-html=dataA |
@@ -161,3 +166,15 @@ remoteFlowSource
161166
| router.js:30:5:30:14 | from.query |
162167
| router.js:34:5:34:12 | to.query |
163168
| router.js:35:5:35:14 | from.query |
169+
parseErrors
170+
attribute
171+
| compont-with-route.vue:2:8:2:21 | v-html=dataA | v-html |
172+
| single-component-file-1.vue:2:8:2:21 | v-html=dataA | v-html |
173+
| single-file-component-2.vue:2:8:2:21 | v-html=dataA | v-html |
174+
| single-file-component-3.vue:2:8:2:21 | v-html=dataA | v-html |
175+
| single-file-component-3.vue:4:9:4:49 | src=./single-file-component-3-script.js | src |
176+
| single-file-component-4.vue:2:8:2:21 | v-html=dataA | v-html |
177+
| single-file-component-5.vue:2:8:2:21 | v-html=dataA | v-html |
178+
| special-syntax.vue:2:9:2:22 | :colonProp=x | :colonProp |
179+
| special-syntax.vue:2:24:2:34 | @atProp=x | @atProp |
180+
| special-syntax.vue:3:9:3:29 | :colonField.field=x | :colonField.field |

javascript/ql/test/library-tests/frameworks/Vue/tests.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ query predicate templateElement(Vue::Template::Element template) { any() }
2020
query predicate xssSink(DomBasedXss::Sink s) { any() }
2121

2222
query RemoteFlowSource remoteFlowSource() { any() }
23+
24+
query predicate parseErrors(JSParseError err) { exists(err) }
25+
26+
query predicate attribute(HTML::Attribute attrib, string name) { attrib.getName() = name }

0 commit comments

Comments
 (0)