Skip to content

Commit 80c5e1e

Browse files
authored
Merge pull request github#14497 from erik-krogh/jsp
JS: add support for extracting `.jsp` files
2 parents c30e004 + 69c3e62 commit 80c5e1e

File tree

6 files changed

+253
-3
lines changed

6 files changed

+253
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
* <li>All JavaScript files, that is, files with one of the extensions supported by {@link
154154
* FileType#JS} (currently ".js", ".jsx", ".mjs", ".cjs", ".es6", ".es").
155155
* <li>All HTML files, that is, files with with one of the extensions supported by {@link
156-
* FileType#HTML} (currently ".htm", ".html", ".xhtm", ".xhtml", ".vue", ".html.erb").
156+
* FileType#HTML} (currently ".htm", ".html", ".xhtm", ".xhtml", ".vue", ".html.erb", ".jsp").
157157
* <li>All YAML files, that is, files with one of the extensions supported by {@link
158158
* FileType#YAML} (currently ".raml", ".yaml", ".yml").
159159
* <li>Files with base name "package.json" or "tsconfig.json", and files whose base name

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static int skipBOM(byte[] bytes, int length) {
103103

104104
/** Information about supported file types. */
105105
public static enum FileType {
106-
HTML(".htm", ".html", ".xhtm", ".xhtml", ".vue", ".hbs", ".ejs", ".njk", ".erb") {
106+
HTML(".htm", ".html", ".xhtm", ".xhtml", ".vue", ".hbs", ".ejs", ".njk", ".erb", ".jsp") {
107107
@Override
108108
public IExtractor mkExtractor(ExtractorConfig config, ExtractorState state) {
109109
return new HTMLExtractor(config, state);

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 = "2023-08-10";
44+
public static final String EXTRACTOR_VERSION = "2023-10-13";
4545

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
2+
<html>
3+
<head>
4+
<title>Hello World JSP</title>
5+
</head>
6+
<body>
7+
<h1>Hello World!</h1>
8+
<% String name = "John"; %>
9+
<p>Welcome <%= name %>!</p>
10+
<script>
11+
console.log(123);
12+
</script>
13+
</body>
14+
</html>
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
#10000=@"/simple-jsp.jsp;sourcefile"
2+
files(#10000,"/simple-jsp.jsp")
3+
#10001=@"/;folder"
4+
folders(#10001,"/")
5+
containerparent(#10001,#10000)
6+
#10002=@"loc,{#10000},0,0,0,0"
7+
locations_default(#10002,#10000,0,0,0,0)
8+
hasLocation(#10000,#10002)
9+
#20000=@"global_scope"
10+
scopes(#20000,0)
11+
#20001=*
12+
#20002=@"script;{#10000},10,13"
13+
#20003=*
14+
lines(#20003,#20002,"","
15+
")
16+
#20004=@"loc,{#10000},10,13,10,12"
17+
locations_default(#20004,#10000,10,13,10,12)
18+
hasLocation(#20003,#20004)
19+
#20005=*
20+
lines(#20005,#20002," console.log(123);","
21+
")
22+
#20006=@"loc,{#10000},11,1,11,23"
23+
locations_default(#20006,#10000,11,1,11,23)
24+
hasLocation(#20005,#20006)
25+
indentation(#10000,11," ",6)
26+
#20007=*
27+
lines(#20007,#20002," ","")
28+
#20008=@"loc,{#10000},12,1,12,4"
29+
locations_default(#20008,#10000,12,1,12,4)
30+
hasLocation(#20007,#20008)
31+
numlines(#20002,3,1,0)
32+
#20009=*
33+
tokeninfo(#20009,6,#20002,0,"console")
34+
#20010=@"loc,{#10000},11,7,11,13"
35+
locations_default(#20010,#10000,11,7,11,13)
36+
hasLocation(#20009,#20010)
37+
#20011=*
38+
tokeninfo(#20011,8,#20002,1,".")
39+
#20012=@"loc,{#10000},11,14,11,14"
40+
locations_default(#20012,#10000,11,14,11,14)
41+
hasLocation(#20011,#20012)
42+
#20013=*
43+
tokeninfo(#20013,6,#20002,2,"log")
44+
#20014=@"loc,{#10000},11,15,11,17"
45+
locations_default(#20014,#10000,11,15,11,17)
46+
hasLocation(#20013,#20014)
47+
#20015=*
48+
tokeninfo(#20015,8,#20002,3,"(")
49+
#20016=@"loc,{#10000},11,18,11,18"
50+
locations_default(#20016,#10000,11,18,11,18)
51+
hasLocation(#20015,#20016)
52+
#20017=*
53+
tokeninfo(#20017,3,#20002,4,"123")
54+
#20018=@"loc,{#10000},11,19,11,21"
55+
locations_default(#20018,#10000,11,19,11,21)
56+
hasLocation(#20017,#20018)
57+
#20019=*
58+
tokeninfo(#20019,8,#20002,5,")")
59+
#20020=@"loc,{#10000},11,22,11,22"
60+
locations_default(#20020,#10000,11,22,11,22)
61+
hasLocation(#20019,#20020)
62+
#20021=*
63+
tokeninfo(#20021,8,#20002,6,";")
64+
#20022=@"loc,{#10000},11,23,11,23"
65+
locations_default(#20022,#10000,11,23,11,23)
66+
hasLocation(#20021,#20022)
67+
#20023=*
68+
tokeninfo(#20023,0,#20002,7,"")
69+
#20024=@"loc,{#10000},12,5,12,4"
70+
locations_default(#20024,#10000,12,5,12,4)
71+
hasLocation(#20023,#20024)
72+
toplevels(#20002,1)
73+
#20025=@"loc,{#10000},10,13,12,4"
74+
locations_default(#20025,#10000,10,13,12,4)
75+
hasLocation(#20002,#20025)
76+
#20026=*
77+
stmts(#20026,2,#20002,0,"console.log(123);")
78+
#20027=@"loc,{#10000},11,7,11,23"
79+
locations_default(#20027,#10000,11,7,11,23)
80+
hasLocation(#20026,#20027)
81+
stmt_containers(#20026,#20002)
82+
#20028=*
83+
exprs(#20028,13,#20026,0,"console.log(123)")
84+
#20029=@"loc,{#10000},11,7,11,22"
85+
locations_default(#20029,#10000,11,7,11,22)
86+
hasLocation(#20028,#20029)
87+
enclosing_stmt(#20028,#20026)
88+
expr_containers(#20028,#20002)
89+
#20030=*
90+
exprs(#20030,14,#20028,-1,"console.log")
91+
#20031=@"loc,{#10000},11,7,11,17"
92+
locations_default(#20031,#10000,11,7,11,17)
93+
hasLocation(#20030,#20031)
94+
enclosing_stmt(#20030,#20026)
95+
expr_containers(#20030,#20002)
96+
#20032=*
97+
exprs(#20032,79,#20030,0,"console")
98+
hasLocation(#20032,#20010)
99+
enclosing_stmt(#20032,#20026)
100+
expr_containers(#20032,#20002)
101+
literals("console","console",#20032)
102+
#20033=@"var;{console};{#20000}"
103+
variables(#20033,"console",#20000)
104+
bind(#20032,#20033)
105+
#20034=*
106+
exprs(#20034,0,#20030,1,"log")
107+
hasLocation(#20034,#20014)
108+
enclosing_stmt(#20034,#20026)
109+
expr_containers(#20034,#20002)
110+
literals("log","log",#20034)
111+
#20035=*
112+
exprs(#20035,3,#20028,0,"123")
113+
hasLocation(#20035,#20018)
114+
enclosing_stmt(#20035,#20026)
115+
expr_containers(#20035,#20002)
116+
literals("123","123",#20035)
117+
#20036=*
118+
entry_cfg_node(#20036,#20002)
119+
hasLocation(#20036,#20004)
120+
#20037=*
121+
exit_cfg_node(#20037,#20002)
122+
hasLocation(#20037,#20024)
123+
successor(#20026,#20032)
124+
successor(#20035,#20028)
125+
successor(#20034,#20030)
126+
successor(#20032,#20034)
127+
successor(#20030,#20035)
128+
successor(#20028,#20037)
129+
successor(#20036,#20026)
130+
toplevel_parent_xml_node(#20002,#20001)
131+
#20038=*
132+
template_placeholder_tag_info(#20038,#10000,"<%@ page contentType=""text/html;charset=UTF-8"" language=""java"" %>")
133+
#20039=@"loc,{#10000},1,1,1,65"
134+
locations_default(#20039,#10000,1,1,1,65)
135+
hasLocation(#20038,#20039)
136+
#20040=*
137+
xmlElements(#20040,"html",#10000,0,#10000)
138+
#20041=@"loc,{#10000},2,1,14,7"
139+
locations_default(#20041,#10000,2,1,14,7)
140+
xmllocations(#20040,#20041)
141+
#20042=*
142+
xmlElements(#20042,"body",#20040,1,#10000)
143+
#20043=@"loc,{#10000},6,3,13,9"
144+
locations_default(#20043,#10000,6,3,13,9)
145+
xmllocations(#20042,#20043)
146+
#20044=*
147+
template_placeholder_tag_info(#20044,#20042,"<% String name = ""John""; %>")
148+
#20045=@"loc,{#10000},8,5,8,31"
149+
locations_default(#20045,#10000,8,5,8,31)
150+
hasLocation(#20044,#20045)
151+
xmlElements(#20001,"script",#20042,2,#10000)
152+
#20046=@"loc,{#10000},10,5,12,13"
153+
locations_default(#20046,#10000,10,5,12,13)
154+
xmllocations(#20001,#20046)
155+
#20047=*
156+
xmlElements(#20047,"p",#20042,1,#10000)
157+
#20048=@"loc,{#10000},9,5,9,31"
158+
locations_default(#20048,#10000,9,5,9,31)
159+
xmllocations(#20047,#20048)
160+
#20049=*
161+
template_placeholder_tag_info(#20049,#20047,"<%= name %>")
162+
#20050=@"loc,{#10000},9,16,9,26"
163+
locations_default(#20050,#10000,9,16,9,26)
164+
hasLocation(#20049,#20050)
165+
scopes(#20000,0)
166+
#20051=@"script;{#10000},9,19"
167+
#20052=*
168+
lines(#20052,#20051," name ","")
169+
#20053=@"loc,{#10000},9,19,9,24"
170+
locations_default(#20053,#10000,9,19,9,24)
171+
hasLocation(#20052,#20053)
172+
indentation(#10000,9," ",1)
173+
numlines(#20051,1,1,0)
174+
#20054=*
175+
tokeninfo(#20054,6,#20051,0,"name")
176+
#20055=@"loc,{#10000},9,20,9,23"
177+
locations_default(#20055,#10000,9,20,9,23)
178+
hasLocation(#20054,#20055)
179+
#20056=*
180+
tokeninfo(#20056,0,#20051,1,"")
181+
#20057=@"loc,{#10000},9,25,9,24"
182+
locations_default(#20057,#10000,9,25,9,24)
183+
hasLocation(#20056,#20057)
184+
toplevels(#20051,4)
185+
hasLocation(#20051,#20053)
186+
#20058=@"module;{#10000},9,19"
187+
scopes(#20058,3)
188+
scopenodes(#20051,#20058)
189+
scopenesting(#20058,#20000)
190+
is_module(#20051)
191+
#20059=*
192+
stmts(#20059,2,#20051,0,"name")
193+
hasLocation(#20059,#20055)
194+
stmt_containers(#20059,#20051)
195+
#20060=*
196+
exprs(#20060,79,#20059,0,"name")
197+
hasLocation(#20060,#20055)
198+
enclosing_stmt(#20060,#20059)
199+
expr_containers(#20060,#20051)
200+
literals("name","name",#20060)
201+
#20061=@"var;{name};{#20058}"
202+
variables(#20061,"name",#20058)
203+
bind(#20060,#20061)
204+
#20062=*
205+
entry_cfg_node(#20062,#20051)
206+
#20063=@"loc,{#10000},9,19,9,18"
207+
locations_default(#20063,#10000,9,19,9,18)
208+
hasLocation(#20062,#20063)
209+
#20064=*
210+
exit_cfg_node(#20064,#20051)
211+
hasLocation(#20064,#20057)
212+
successor(#20059,#20060)
213+
successor(#20060,#20064)
214+
successor(#20062,#20059)
215+
toplevel_parent_xml_node(#20051,#20049)
216+
#20065=*
217+
xmlElements(#20065,"h1",#20042,0,#10000)
218+
#20066=@"loc,{#10000},7,5,7,25"
219+
locations_default(#20066,#10000,7,5,7,25)
220+
xmllocations(#20065,#20066)
221+
#20067=*
222+
xmlElements(#20067,"head",#20040,0,#10000)
223+
#20068=@"loc,{#10000},3,3,5,9"
224+
locations_default(#20068,#10000,3,3,5,9)
225+
xmllocations(#20067,#20068)
226+
#20069=*
227+
xmlElements(#20069,"title",#20067,0,#10000)
228+
#20070=@"loc,{#10000},4,5,4,34"
229+
locations_default(#20070,#10000,4,5,4,34)
230+
xmllocations(#20069,#20070)
231+
numlines(#10000,14,2,0)
232+
filetype(#10000,"html")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The contents of `.jsp` files are now extracted, and any `<script>` tags inside these files will be parsed as JavaScript.

0 commit comments

Comments
 (0)