private void doContextualEscaping(SoyFileSetNode soyTree) throws SoySyntaxException { List<TemplateNode> extraTemplates = contextualAutoescaper.rewrite(soyTree); // TODO: Run the redundant template remover here and rename after CL 16642341 is in. if (!extraTemplates.isEmpty()) { // TODO: pull out somewhere else. Ideally do the merge as part of the redundant template // removal. Map<String, SoyFileNode> containingFile = Maps.newHashMap(); for (SoyFileNode fileNode : soyTree.getChildren()) { for (TemplateNode templateNode : fileNode.getChildren()) { String name = templateNode instanceof TemplateDelegateNode ? ((TemplateDelegateNode) templateNode).getDelTemplateName() : templateNode.getTemplateName(); containingFile.put(DerivedTemplateUtils.getBaseName(name), fileNode); } } for (TemplateNode extraTemplate : extraTemplates) { String name = extraTemplate instanceof TemplateDelegateNode ? ((TemplateDelegateNode) extraTemplate).getDelTemplateName() : extraTemplate.getTemplateName(); containingFile.get(DerivedTemplateUtils.getBaseName(name)).addChild(extraTemplate); } } }
/** Visits a {@link SoyFileNode}, making sure it has strict autoescape. */ @Override protected void visitSoyFileNode(SoyFileNode node) { if (node.getDefaultAutoescapeMode() != AutoescapeMode.STRICT) { errorReporter.report(node.getSourceLocation(), NON_STRICT_FILE); } visitChildren(node); }
@Override protected void visitSoyFileNode(SoyFileNode node) { if (node.getDefaultAutoescapeMode() != AutoescapeMode.STRICT) { errorReporter.report(node.getSourceLocation(), INVALID_AUTOESCAPING); // If the file isn't strict, skip children to avoid spamming errors. return; } visitChildren(node); }
private SoyFileSetNode parseAndInjectIntoScriptTags(String input, String toInject) { String namespace = "{namespace ns autoescape=\"deprecated-contextual\"}\n\n"; ErrorReporter boom = ExplodingErrorReporter.get(); SoyFileSetNode soyTree = SoyFileSetParserBuilder.forFileContents(namespace + input).errorReporter(boom).parse(); ContextualAutoescaper contextualAutoescaper = new ContextualAutoescaper(SOY_PRINT_DIRECTIVES, boom); List<TemplateNode> extras = contextualAutoescaper.rewrite(soyTree); SoyFileNode file = soyTree.getChild(soyTree.numChildren() - 1); file.addChildren(file.numChildren(), extras); insertTextAtEndOfScriptOpenTag(contextualAutoescaper.getSlicedRawTextNodes(), toInject); return soyTree; }
@Override protected void visitSoyFileNode(SoyFileNode node) { currNamespace = node.getNamespace(); if (currNamespace != null) { visitChildren(node); } currNamespace = null; }