Merge pull request #5107 from asgerf/js/json-in-script-tag

Approved by erik-krogh
This commit is contained in:
CodeQL CI
2021-02-08 09:52:53 +00:00
committed by GitHub
4 changed files with 44 additions and 2 deletions

View File

@@ -331,7 +331,10 @@ public class HTMLExtractor implements IExtractor {
textualExtractor.getMetrics(),
textualExtractor.getExtractedFile());
Pair<Label, LoCInfo> result = extractor.extract(tx, source, toplevelKind, scopeManager);
emitTopLevelXmlNodeBinding(parentHtmlNode, result.fst(), context, trapWriter);
Label toplevelLabel = result.fst();
if (toplevelLabel != null) { // can be null when script ends up being parsed as JSON
emitTopLevelXmlNodeBinding(parentHtmlNode, toplevelLabel, context, trapWriter);
}
locInfo.add(result.snd());
} catch (ParseError e) {
e.setPosition(scriptLocationManager.translatePosition(e.getPosition()));

View File

@@ -43,7 +43,7 @@ public class Main {
* A version identifier that should be updated every time the extractor changes in such a way that
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
*/
public static final String EXTRACTOR_VERSION = "2020-12-11";
public static final String EXTRACTOR_VERSION = "2021-02-05";
public static final Pattern NEWLINE = Pattern.compile("\n");

View File

@@ -0,0 +1,5 @@
<html>
<script>
{"Hello": 123}
</script>
</html>

View File

@@ -0,0 +1,34 @@
#10000=@"/json_in_script.html;sourcefile"
files(#10000,"/json_in_script.html","json_in_script","html",0)
#10001=@"/;folder"
folders(#10001,"/","")
containerparent(#10001,#10000)
#10002=@"loc,{#10000},0,0,0,0"
locations_default(#10002,#10000,0,0,0,0)
hasLocation(#10000,#10002)
#20000=@"global_scope"
scopes(#20000,0)
#20001=*
json(#20001,5,#10000,0,"{""Hello"": 123}")
#20002=@"loc,{#10000},3,1,3,14"
locations_default(#20002,#10000,3,1,3,14)
json_locations(#20001,#20002)
#20003=*
json(#20003,2,#20001,0,"123")
#20004=@"loc,{#10000},3,11,3,13"
locations_default(#20004,#10000,3,11,3,13)
json_locations(#20003,#20004)
json_literals("123","123",#20003)
json_properties(#20001,"Hello",#20003)
#20005=*
xmlElements(#20005,"html",#10000,0,#10000)
#20006=@"loc,{#10000},1,1,5,7"
locations_default(#20006,#10000,1,1,5,7)
xmllocations(#20005,#20006)
#20007=*
xmlElements(#20007,"script",#20005,0,#10000)
#20008=@"loc,{#10000},2,1,4,9"
locations_default(#20008,#10000,2,1,4,9)
xmllocations(#20007,#20008)
numlines(#10000,5,0,0)
filetype(#10000,"html")