JS: Tolerate JSON in script tags

This commit is contained in:
Asger Feldthaus
2021-02-05 21:54:50 +00:00
parent a45c415c5b
commit 236b7c5887
3 changed files with 43 additions and 1 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()));