diff options
author | Nathaniel Guse <nathaniel.guse@gmail.com> | 2013-07-19 14:12:28 -0500 |
---|---|---|
committer | Nathaniel Guse <nathaniel.guse@gmail.com> | 2013-07-19 14:12:28 -0500 |
commit | 375976eb38882f42155f1f7fa2c849add8dbcf08 (patch) | |
tree | c6c27f97d7c370352ea44d324b8ebb25c4b25373 | |
parent | 29322e85ff31d1a71a07846241dd809972323340 (diff) | |
download | forums-375976eb38882f42155f1f7fa2c849add8dbcf08.tar forums-375976eb38882f42155f1f7fa2c849add8dbcf08.tar.gz forums-375976eb38882f42155f1f7fa2c849add8dbcf08.tar.bz2 forums-375976eb38882f42155f1f7fa2c849add8dbcf08.tar.xz forums-375976eb38882f42155f1f7fa2c849add8dbcf08.zip |
[ticket/11707] Twig DEFINE not working as expected
PHPBB3-11707
-rw-r--r-- | phpBB/phpbb/template/twig/lexer.php | 12 | ||||
-rw-r--r-- | tests/template/template_test.php | 2 | ||||
-rw-r--r-- | tests/template/templates/define.html | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 46412ad048..1fa4c5b3e6 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -126,10 +126,14 @@ class phpbb_template_twig_lexer extends Twig_Lexer { $callback = function($matches) { - // Remove any quotes that may have been used in different implementations - // E.g. DEFINE $TEST = 'blah' vs INCLUDE foo - // Replace {} with start/end to parse variables (' ~ TEST ~ '.html) - $matches[2] = str_replace(array('"', "'", '{', '}'), array('', '', "' ~ ", " ~ '"), $matches[2]); + // Remove matching quotes at the beginning/end if a statement; + // E.g. 'asdf'"' -> asdf'" + // E.g. "asdf'"" -> asdf'" + // E.g. 'asdf'" -> 'asdf'" + $matches[2] = preg_replace('#^([\'"])?(.+?)\1$#', '$2', $matches[2]); + + // Replace template variables with start/end to parse variables (' ~ TEST ~ '.html) + $matches[2] = preg_replace('#{([a-zA-Z0-9_\.$]+)}#', "'~ \$1 ~'", $matches[2]); // Surround the matches in single quotes ('' ~ TEST ~ '.html') return "<!-- {$matches[1]} '{$matches[2]}' -->"; diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 802f0c19ba..2ed0f03698 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -151,7 +151,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc\nabc\nbar\nbar\nabc", + "xyz\nabc\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 4e6d0ee793..f0df16a8f8 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -7,3 +7,5 @@ {$VALUE} <!-- UNDEFINE $VALUE --> {$VALUE} +<!-- DEFINE $VALUE = 'test!@#$%^&*()_-=+{}[]:;",<.>/?' --> +{$VALUE} |