mirror of
https://github.com/Mibew/handlebars.php.git
synced 2024-11-15 08:44:12 +03:00
Implemented proper treatment of brackets inside string arguments in subexpressions ( {{foo '(bar)'}} )
This commit is contained in:
parent
5a58d27ad3
commit
ffcbecf346
@ -275,17 +275,30 @@ class Template
|
||||
|
||||
// subexpression parsing loop
|
||||
$subexprs = array(); // will contain all subexpressions inside outermost brackets
|
||||
$inside_of = array( 'single' => false, 'double' => false );
|
||||
$lvl = 0;
|
||||
$cur_start = 0;
|
||||
for ($i=0; $i < strlen($params[2]); $i++) {
|
||||
$cur = substr($params[2], $i, 1);
|
||||
if ($cur == '(') {
|
||||
if( $lvl == 0 ) $cur_start = $i+1;
|
||||
$lvl++;
|
||||
if ($cur == "'" ) {
|
||||
$inside_of['single'] = ! $inside_of['single'];
|
||||
}
|
||||
if ($cur == ')') {
|
||||
if ($cur == '"' ) {
|
||||
$inside_of['double'] = ! $inside_of['double'];
|
||||
}
|
||||
if ($cur == '(' && ! $inside_of['single'] && ! $inside_of['double']) {
|
||||
if ($lvl == 0) {
|
||||
$cur_start = $i+1;
|
||||
}
|
||||
$lvl++;
|
||||
continue;
|
||||
}
|
||||
if ($cur == ')' && ! $inside_of['single'] && ! $inside_of['double']) {
|
||||
$lvl--;
|
||||
if ($lvl == 0) $subexprs[] = substr($params[2], $cur_start, $i - $cur_start);
|
||||
if ($lvl == 0) {
|
||||
$subexprs[] = substr($params[2], $cur_start, $i - $cur_start);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -300,7 +313,7 @@ class Template
|
||||
Tokenizer::OTAG => $current[Tokenizer::OTAG],
|
||||
Tokenizer::CTAG => $current[Tokenizer::CTAG],
|
||||
Tokenizer::INDEX => $current[Tokenizer::INDEX],
|
||||
Tokenizer::ARGS => implode(" ", array_slice( $cmd, 1 ))
|
||||
Tokenizer::ARGS => implode(" ", array_slice($cmd, 1))
|
||||
);
|
||||
// resolve the node recursively
|
||||
$resolved = $this->_handlebarsStyleSection($context, $section_node);
|
||||
|
Loading…
Reference in New Issue
Block a user