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

SafeString fails with FLAG_EXTHELPER | FLAG_BESTPERFORMANCE #354

Open
storeman opened this issue Aug 25, 2021 · 0 comments
Open

SafeString fails with FLAG_EXTHELPER | FLAG_BESTPERFORMANCE #354

storeman opened this issue Aug 25, 2021 · 0 comments

Comments

@storeman
Copy link

storeman commented Aug 25, 2021

The PHP Code:

require('./vendor/autoload.php');
use LightnCandy\LightnCandy;

class HelperClass
{
    public static function printStrong ($value)
    {
        return new \LightnCandy\SafeString('<strong>'.$value.'</strong>');
    }
}


// The Template:
$template = <<<VAREND
{{ PrintStrong "Hello world" }}
VAREND;


$phpStr = LightnCandy::compile($template, array(
    // Used compile flags
    'flags' => LightnCandy::FLAG_HANDLEBARS
        | LightnCandy::FLAG_BESTPERFORMANCE
        | LightnCandy::FLAG_EXTHELPER,
    'helpers' => [
        'PrintStrong' => HelperClass::class . '::printStrong'
    ],
));

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:

I expect to get the normal HTML returned. When omitting LightnCandy::FLAG_BESTPERFORMANCE or LightnCandy::FLAG_EXTHELPER, it works as expected.

But when both flags are set, the HTML is escaped, thus SafeString is ignored.

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

No branches or pull requests

1 participant