summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/NodeVisitor/SafeAnalysis.php
diff options
context:
space:
mode:
authorBenjamin Southall <applemansigloo@gmail.com>2019-02-26 10:11:12 +1000
committerBenjamin Southall <applemansigloo@gmail.com>2019-02-26 10:11:12 +1000
commitf79395851b044689567e0e6c9504acbcaa742782 (patch)
treeee539aee9ffa90e8accd6f130b30a8ebed7a232e /inc/lib/Twig/NodeVisitor/SafeAnalysis.php
parent28f32baf0125ca5085266e73dc5071e5814d8e3b (diff)
Twig update to latest Twig 1.x legacy as per vichan
Diffstat (limited to 'inc/lib/Twig/NodeVisitor/SafeAnalysis.php')
-rw-r--r--inc/lib/Twig/NodeVisitor/SafeAnalysis.php43
1 files changed, 30 insertions, 13 deletions
diff --git a/inc/lib/Twig/NodeVisitor/SafeAnalysis.php b/inc/lib/Twig/NodeVisitor/SafeAnalysis.php
index b0c658cd..ca31c8fc 100644
--- a/inc/lib/Twig/NodeVisitor/SafeAnalysis.php
+++ b/inc/lib/Twig/NodeVisitor/SafeAnalysis.php
@@ -1,6 +1,18 @@
<?php
-class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * @final
+ */
+class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor
{
protected $data = array();
protected $safeVars = array();
@@ -13,12 +25,20 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
public function getSafe(Twig_NodeInterface $node)
{
$hash = spl_object_hash($node);
- if (isset($this->data[$hash])) {
- foreach ($this->data[$hash] as $bucket) {
- if ($bucket['key'] === $node) {
- return $bucket['value'];
- }
+ if (!isset($this->data[$hash])) {
+ return;
+ }
+
+ foreach ($this->data[$hash] as $bucket) {
+ if ($bucket['key'] !== $node) {
+ continue;
}
+
+ if (in_array('html_attr', $bucket['value'])) {
+ $bucket['value'][] = 'html';
+ }
+
+ return $bucket['value'];
}
}
@@ -40,12 +60,12 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
);
}
- public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
+ protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{
return $node;
}
- public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
+ protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Expression_Constant) {
// constants are marked safe for all
@@ -89,8 +109,6 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
} else {
$this->setSafe($node, array());
}
- } elseif ($node instanceof Twig_Node_Expression_MacroCall) {
- $this->setSafe($node, array('all'));
} elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) {
$name = $node->getNode('node')->getAttribute('name');
// attributes on template instances are safe
@@ -123,11 +141,10 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
return array_intersect($a, $b);
}
- /**
- * {@inheritdoc}
- */
public function getPriority()
{
return 0;
}
}
+
+class_alias('Twig_NodeVisitor_SafeAnalysis', 'Twig\NodeVisitor\SafeAnalysisNodeVisitor', false);