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

Broken custom delimiters when combined with { } at 3.1.32 #450

Closed
RYRDU opened this issue May 31, 2018 · 1 comment
Closed

Broken custom delimiters when combined with { } at 3.1.32 #450

RYRDU opened this issue May 31, 2018 · 1 comment

Comments

@RYRDU
Copy link

RYRDU commented May 31, 2018

I want to use this style delimiters

$smarty->left_delimiter = '{^';
$smarty->right_delimiter = '^}';

This will produce the following exception
Line 357 at file: smarty\libs\sysplugins\smarty_internal_templatelexer.php

I am positive everything was working fine at 3.1.31

I try to solve the problem, so I edited the function initDelimiterPreg in smarty_internal_templatecompilerbase.php

/**
 * Build lexer regular expressions for left and right delimiter and user defined literals
 */
public function initDelimiterPreg()
{
    $ldel = $this->smarty->getLeftDelimiter();
    $this->ldelLength = strlen($ldel);
    $this->ldelPreg = '';
    foreach (str_split($ldel, 1) as $chr) {
        $chr = preg_quote($chr, '/');
        $this->ldelPreg .= '[' . ($chr === '\\' ? '\\' : '') . $chr . ']';
    }

    $rdel = $this->smarty->getRightDelimiter();
    $this->rdelLength = strlen($rdel);
    $this->rdelPreg = '';
    foreach (str_split($rdel, 1) as $chr) {
        $chr = preg_quote($chr, '/');
        $this->rdelPreg .= '[' . ($chr === '\\' ? '\\' : '') . $chr . ']';
    }
    $literals = $this->smarty->getLiterals();
    if (!empty($literals)) {
        foreach ($literals as $key => $literal) {
            $literalPreg = '';
            foreach (str_split($literal, 1) as $chr) {
                $literalPreg .= '[' . ($chr === '\\' ? '\\' : '') . $chr . ']';
            }
            $literals[ $key ] = $literalPreg;
        }
        $this->literalPreg = '|' . implode('|', $literals);
    } else {
        $this->literalPreg = '';
    }
}
@artemsuv
Copy link

Make pull request #482

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

3 participants