lightncandy
lightncandy copied to clipboard
Including an escaped double quote followed by a space in helper arguments throws a Fatal Error.
trafficstars
The PHP Code:
<?php
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
// The Template:
$template = <<<VAREND
{{test "foo" prop="\" "}}
VAREND;
// Helpers:
$helpers = array(
'test' => function ($viewName, $options) {
return $options['hash']['prop'];
},
);
// Partials:
$partials = array(
'bar' => 'Yes, partial',
);
$phpStr = LightnCandy::compile($template, array(
// Used compile flags
'flags' => LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_HANDLEBARS,
'helpers' => $helpers,
'partials' => $partials,
));
echo "Generated PHP Code:\n$phpStr\n";
// Input Data:
$data = array();
// Save the compiled PHP code into a php file
file_put_contents('render.php', '<?php ' . $phpStr . '?>');
// Get the render function from the php file
$renderer = include('render.php');
echo "Result:\n" . $renderer($data);
The Issue:
Including an escaped double quote followed by a space in helper arguments throws a Fatal Error:
Fatal error: Uncaught Exception: Error in 'new "foo" prop="\\" "': expect '"' but the token ended!! in [path]/vendor/zordius/lightncandy/src/LightnCandy.php:110
Stack trace:
#0 [path]/vendor/zordius/lightncandy/src/LightnCandy.php(55): LightnCandy\LightnCandy::handleError(Array)
#1 [path]/test.php(27): LightnCandy\LightnCandy::compile('{{new "foo" pro...', Array)
#2 {main}
thrown in [path]/vendor/zordius/lightncandy/src/LightnCandy.php on line 110
This issue only presents when the escaped double quote is directly followed by a space: {{test "foo" prop="\""}} renders " as expected.
I can confirm that this issue is still present in LightnCandy 1.2.5. Here is the current stack trace
PHP Fatal error: Uncaught Exception: Error in 'echo message="\\\\" "': expect '"' but the token ended!! in vendor/zordius/lightncandy/src/LightnCandy.php:108
Stack trace:
#0 vendor/zordius/lightncandy/src/LightnCandy.php(50): LightnCandy\\LightnCandy::handleError()
#1 test.php(34): LightnCandy\\LightnCandy::compile()
#2 {main}
thrown in vendor/zordius/lightncandy/src/LightnCandy.php on line 108