Skip to content

Commit 3879e57

Browse files
author
Esben Sparre Andreasen
committed
JS: support <meta name="generator"/> classification
1 parent a295dfd commit 3879e57

File tree

7 files changed

+67
-2
lines changed

7 files changed

+67
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ private predicate isData(File f) {
114114
)
115115
}
116116

117+
/**
118+
* Holds if `f` is a generated HTML file.
119+
*/
120+
private predicate isGeneratedHtml(File f) {
121+
exists(HTML::Element e |
122+
e.getFile() = f and
123+
e.getName() = "meta" and
124+
e.getAttributeByName("name").getValue() = "generator"
125+
)
126+
}
127+
117128
/**
118129
* Holds if `tl` looks like it contains generated code.
119130
*/
@@ -124,12 +135,14 @@ predicate isGenerated(TopLevel tl) {
124135
tl instanceof DartGeneratedTopLevel or
125136
exists (GeneratedCodeMarkerComment gcmc | tl = gcmc.getTopLevel()) or
126137
hasManyInvocations(tl) or
127-
isData(tl.getFile())
138+
isData(tl.getFile()) or
139+
isGeneratedHtml(tl.getFile())
128140
}
129141

130142
/**
131143
* Holds if `file` look like it contains generated code.
132144
*/
133145
predicate isGeneratedCode(File file) {
134-
isGenerated(file.getATopLevel())
146+
isGenerated(file.getATopLevel()) or
147+
isGeneratedHtml(file)
135148
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
| ai.1.2.3-build0123.js:0:0:0:0 | ai.1.2.3-build0123.js | library |
33
| bundle-directive.js:0:0:0:0 | bundle-directive.js | generated |
44
| data.js:0:0:0:0 | data.js | generated |
5+
| etherpad.html:0:0:0:0 | etherpad.html | generated |
56
| exported-data.js:0:0:0:0 | exported-data.js | generated |
7+
| htmltidy.html:0:0:0:0 | htmltidy.html | generated |
68
| jison-lex.js:0:0:0:0 | jison-lex.js | generated |
79
| jison.js:0:0:0:0 | jison.js | generated |
810
| jquery-datatables.js:0:0:0:0 | jquery-datatables.js | library |
@@ -15,10 +17,13 @@
1517
| multiple-licenses-2.js:0:0:0:0 | multiple-licenses-2.js | generated |
1618
| multiple-licenses.js:0:0:0:0 | multiple-licenses.js | generated |
1719
| opal-test.js:0:0:0:0 | opal-test.js | generated |
20+
| orgmode.html:0:0:0:0 | orgmode.html | generated |
21+
| pandoc.html:0:0:0:0 | pandoc.html | generated |
1822
| peg-js.js:0:0:0:0 | peg-js.js | generated |
1923
| polymer.html:0:0:0:0 | polymer.html | template |
2024
| some-template.html:0:0:0:0 | some-template.html | template |
2125
| templ.js:0:0:0:0 | templ.js | template |
26+
| textmate.html:0:0:0:0 | textmate.html | generated |
2227
| tmpl2.html:0:0:0:0 | tmpl2.html | template |
2328
| tmpl.html:0:0:0:0 | tmpl.html | template |
2429
| tst.browserify.js:0:0:0:0 | tst.browserify.js | generated |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title><%- padId %></title>
5+
<meta name="generator" content="Etherpad">
6+
<script type="text/javascript">//</script>
7+
</head>
8+
<body>
9+
</body>
10+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
2+
<html>
3+
<head>
4+
<meta name="generator" content="HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org">
5+
<script type="text/javascript">//</script>
6+
</head>
7+
<body>
8+
</body>
9+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
5+
<head>
6+
<meta name="generator" content="Org-mode"/>
7+
<script type="text/javascript">//</script>
8+
</head>
9+
<body>
10+
</body>
11+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="generator" content="pandoc" />
5+
<script type="text/javascript">//</script>
6+
</head>
7+
<body>
8+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
2+
"http://www.w3.org/TR/html4/strict.dtd">
3+
<html lang="en">
4+
<head>
5+
<meta name="generator" content="TextMate http://macromates.com/">
6+
<script type="text/javascript">//</script>
7+
</head>
8+
<body>
9+
</html>

0 commit comments

Comments
 (0)