phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
62 stars 3 forks source link

Error while executing php code #36

Closed rodion-k closed 6 years ago

rodion-k commented 6 years ago

Hello,

This code throws exception

Phug\Phug::render('- "#{}"');
syntax error, unexpected ')'
#0 /vendor/phug/renderer/src/Phug/Renderer/AbstractAdapter.php(41): Phug\Renderer\Adapter\EvalAdapter->display('<?php \n\\Phug\\Re...', Array)
#1 /vendor/phug/util/src/Phug/Util/SandBox.php(38): Phug\Renderer\AbstractAdapter->Phug\Renderer\{closure}()
#2 /vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(100): Phug\Util\SandBox->__construct(Object(Closure), NULL)
#3 /vendor/phug/renderer/src/Phug/Renderer/AbstractAdapter.php(29): Phug\Renderer->getNewSandBox(Object(Closure))
#4 /vendor/phug/renderer/src/Phug/Renderer/AbstractAdapter.php(42): Phug\Renderer\AbstractAdapter->captureBuffer(Object(Closure))
#5 /vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(140): Phug\Renderer\AbstractAdapter->render('<?php \n\\Phug\\Re...', Array)
#6 /vendor/phug/util/src/Phug/Util/SandBox.php(38): Phug\Renderer->Phug\Renderer\Partial\{closure}()
#7 /vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(100): Phug\Util\SandBox->__construct(Object(Closure), NULL)
#8 /vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(142): Phug\Renderer->getNewSandBox(Object(Closure))
#9 /vendor/phug/renderer/src/Phug/Renderer/Partial/AdapterTrait.php(207): Phug\Renderer->getSandboxCall('<?php \n\\Phug\\Re...', 'render', NULL, '- "#{}"', Object(Closure), Array)
#10 /vendor/phug/renderer/src/Phug/Renderer.php(114): Phug\Renderer->callAdapter('render', NULL, '- "#{}"', Object(Closure), Array)
#11 /vendor/phug/phug/src/Phug/Phug.php(170): Phug\Renderer->render('- "#{}"', Array)

Thanks!

kylekatarnls commented 6 years ago

Infact, - "#{}" is not a valid pug code: an interpolation should not be empty, and if it's not an interpolation, you must escape it:

- $a = "\#{}"
=$a
rodion-k commented 6 years ago

I thought interpolation shouldn't work in code. Seems in pugjs it does not work

-
  var name = 'value';
  var a = '#{name}';
= a

gives #{name}

https://codepen.io/rodion-k/pen/zawwZL

kylekatarnls commented 6 years ago

Yes, it's what we discussed with @TorbenKoehn I try to know why the engine do so and if it's a regression.

kylekatarnls commented 6 years ago

Hi @rodion-k please run composer update and tell me if it fixes your problem. Now code elements are no longer considered as interpolable.