Skip to content

Commit 8604057

Browse files
authored
Merge pull request #1161 from esben-semmle/js/classify-mode-html
Approved by xiemaisi
2 parents debc441 + bf04664 commit 8604057

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

javascript/ql/src/semmle/javascript/GeneratedCode.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ private predicate isGeneratedHtml(File f) {
121121
e.getName() = "meta" and
122122
e.getAttributeByName("name").getValue() = "generator"
123123
)
124+
or
125+
20 < countStartingHtmlElements(f, _)
126+
}
127+
128+
/**
129+
* Gets an element that starts at line `l` in file `f`.
130+
*/
131+
private HTML::Element getAStartingElement(File f, int l) {
132+
result.getFile() = f and result.getLocation().getStartLine() = l
133+
}
134+
135+
136+
/**
137+
* Gets the number of HTML elements that start at line `l` in file `f`.
138+
*/
139+
private int countStartingHtmlElements(File f, int l) {
140+
result = strictcount(getAStartingElement(f, l))
124141
}
125142

126143
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<html>
2+
<div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
3+
<script>42</script>
4+
</html>

javascript/ql/test/query-tests/filters/ClassifyFiles/ClassifyFiles.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| AutoRest.js:0:0:0:0 | AutoRest.js | generated |
2+
| ManyElementsOnLine.html:0:0:0:0 | ManyElementsOnLine.html | generated |
23
| ai.1.2.3-build0123.js:0:0:0:0 | ai.1.2.3-build0123.js | library |
34
| bundle-directive.js:0:0:0:0 | bundle-directive.js | generated |
45
| data.js:0:0:0:0 | data.js | generated |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<html>
2+
<div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
3+
<script>42</script>
4+
</html>

0 commit comments

Comments
 (0)