Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.8.0 - PHP error in EscaperNodeVisitor::unwrapConditional() #2942

Closed
brandonkelly opened this issue Apr 16, 2019 · 7 comments
Closed

v2.8.0 - PHP error in EscaperNodeVisitor::unwrapConditional() #2942

brandonkelly opened this issue Apr 16, 2019 · 7 comments

Comments

@brandonkelly
Copy link
Contributor

As of Twig v2.8.0 I’m getting the following error:

TypeError: Argument 1 passed to Twig\NodeVisitor\EscaperNodeVisitor::shouldUnwrapConditional() must be an instance of Twig\Node\Expression\ConditionalExpression, instance of Twig\Node\Expression\InlinePrint given, called in /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php on line 110 and defined in /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php:92
Stack trace:
#0 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php(110): Twig\NodeVisitor\EscaperNodeVisitor->shouldUnwrapConditional(Object(Twig\Node\Expression\InlinePrint), Object(craft\web\twig\Environment), 'html')
#1 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeVisitor/EscaperNodeVisitor.php(77): Twig\NodeVisitor\EscaperNodeVisitor->unwrapConditional(Object(Twig\Node\Expression\ConditionalExpression), Object(craft\web\twig\Environment), 'html')
#2 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeVisitor/AbstractNodeVisitor.php(31): Twig\NodeVisitor\EscaperNodeVisitor->doLeaveNode(Object(Twig\Node\PrintNode), Object(craft\web\twig\Environment))
#3 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeTraverser.php(77): Twig\NodeVisitor\AbstractNodeVisitor->leaveNode(Object(Twig\Node\PrintNode), Object(craft\web\twig\Environment))
#4 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeTraverser.php(68): Twig\NodeTraverser->traverseForVisitor(Object(Twig\NodeVisitor\EscaperNodeVisitor), Object(Twig\Node\PrintNode))
#5 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeTraverser.php(68): Twig\NodeTraverser->traverseForVisitor(Object(Twig\NodeVisitor\EscaperNodeVisitor), Object(Twig\Node\Node))
#6 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeTraverser.php(68): Twig\NodeTraverser->traverseForVisitor(Object(Twig\NodeVisitor\EscaperNodeVisitor), Object(Twig\Node\Node))
#7 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeTraverser.php(68): Twig\NodeTraverser->traverseForVisitor(Object(Twig\NodeVisitor\EscaperNodeVisitor), Object(Twig\Node\IfNode))
#8 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeTraverser.php(68): Twig\NodeTraverser->traverseForVisitor(Object(Twig\NodeVisitor\EscaperNodeVisitor), Object(Twig\Node\Node))
#9 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeTraverser.php(68): Twig\NodeTraverser->traverseForVisitor(Object(Twig\NodeVisitor\EscaperNodeVisitor), Object(Twig\Node\BodyNode))
#10 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/NodeTraverser.php(53): Twig\NodeTraverser->traverseForVisitor(Object(Twig\NodeVisitor\EscaperNodeVisitor), Object(Twig\Node\ModuleNode))
#11 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/Parser.php(119): Twig\NodeTraverser->traverse(Object(Twig\Node\ModuleNode))
#12 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/Environment.php(574): Twig\Parser->parse(Object(Twig\TokenStream))
#13 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/Environment.php(606): Twig\Environment->parse(Object(Twig\TokenStream))
#14 /home/vagrant/dev/craft31/src/web/twig/Environment.php(63): Twig\Environment->compileSource(Object(Twig\Source))
#15 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/Environment.php(407): craft\web\twig\Environment->compileSource(Object(Twig\Source))
#16 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/Environment.php(381): Twig\Environment->loadClass('__TwigTemplate_...', '_includes/forms...', NULL)
#17 /home/vagrant/dev/craft31/src/web/twig/Environment.php(44): Twig\Environment->loadTemplate('_includes/forms...', NULL)
#18 /home/vagrant/dev/craft31.test/vendor/twig/twig/src/Template.php(324): craft\web\twig\Environment->loadTemplate('_includes/forms...', NULL)

Looks like maybe $expr2 should be $expr3 on this line:

if ($expr3 instanceof ConditionalExpression && $this->shouldUnwrapConditional($expr2, $env, $type)) {

brandonkelly added a commit to craftcms/cms that referenced this issue Apr 16, 2019
@stof
Copy link
Member

stof commented Apr 16, 2019

can you send a PR ?

@brandonkelly
Copy link
Contributor Author

I’m not familiar with that part of the code so not confident enough about the fix to submit a PR.

@stof
Copy link
Member

stof commented Apr 16, 2019

Well, the line to change is the one you identified. And using the right variable is indeed what should be done.

@fabpot
Copy link
Contributor

fabpot commented Apr 16, 2019

@brandonkelly I'm going to make the fix and a new release.

@fabpot fabpot mentioned this issue Apr 16, 2019
@fabpot
Copy link
Contributor

fabpot commented Apr 16, 2019

see #2943

@fabpot fabpot closed this as completed Apr 16, 2019
fabpot added a commit that referenced this issue Apr 16, 2019
This PR was merged into the 1.x branch.

Discussion
----------

Hotfix

closes #2942

Commits
-------

a3fc639 fixed EscaperNodeVisitor
@brandonkelly
Copy link
Contributor Author

Thanks @fabpot!

@fabpot
Copy link
Contributor

fabpot commented Apr 16, 2019

Versions 1.39.1 and 2.8.1 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants