Skip to content

Commit 8a2e063

Browse files
authored
Merge pull request github#5107 from asgerf/js/json-in-script-tag
Approved by erik-krogh
2 parents 7859c52 + 0ceb8aa commit 8a2e063

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ private void extractSnippet(
331331
textualExtractor.getMetrics(),
332332
textualExtractor.getExtractedFile());
333333
Pair<Label, LoCInfo> result = extractor.extract(tx, source, toplevelKind, scopeManager);
334-
emitTopLevelXmlNodeBinding(parentHtmlNode, result.fst(), context, trapWriter);
334+
Label toplevelLabel = result.fst();
335+
if (toplevelLabel != null) { // can be null when script ends up being parsed as JSON
336+
emitTopLevelXmlNodeBinding(parentHtmlNode, toplevelLabel, context, trapWriter);
337+
}
335338
locInfo.add(result.snd());
336339
} catch (ParseError e) {
337340
e.setPosition(scriptLocationManager.translatePosition(e.getPosition()));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Main {
4343
* A version identifier that should be updated every time the extractor changes in such a way that
4444
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4545
*/
46-
public static final String EXTRACTOR_VERSION = "2020-12-11";
46+
public static final String EXTRACTOR_VERSION = "2021-02-05";
4747

4848
public static final Pattern NEWLINE = Pattern.compile("\n");
4949

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<script>
3+
{"Hello": 123}
4+
</script>
5+
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#10000=@"/json_in_script.html;sourcefile"
2+
files(#10000,"/json_in_script.html","json_in_script","html",0)
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+
json(#20001,5,#10000,0,"{""Hello"": 123}")
13+
#20002=@"loc,{#10000},3,1,3,14"
14+
locations_default(#20002,#10000,3,1,3,14)
15+
json_locations(#20001,#20002)
16+
#20003=*
17+
json(#20003,2,#20001,0,"123")
18+
#20004=@"loc,{#10000},3,11,3,13"
19+
locations_default(#20004,#10000,3,11,3,13)
20+
json_locations(#20003,#20004)
21+
json_literals("123","123",#20003)
22+
json_properties(#20001,"Hello",#20003)
23+
#20005=*
24+
xmlElements(#20005,"html",#10000,0,#10000)
25+
#20006=@"loc,{#10000},1,1,5,7"
26+
locations_default(#20006,#10000,1,1,5,7)
27+
xmllocations(#20005,#20006)
28+
#20007=*
29+
xmlElements(#20007,"script",#20005,0,#10000)
30+
#20008=@"loc,{#10000},2,1,4,9"
31+
locations_default(#20008,#10000,2,1,4,9)
32+
xmllocations(#20007,#20008)
33+
numlines(#10000,5,0,0)
34+
filetype(#10000,"html")

0 commit comments

Comments
 (0)