aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/template/twig/lexer.php
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-11-08 22:30:58 -0600
committerNathan Guse <nathaniel.guse@gmail.com>2013-11-08 22:30:58 -0600
commit6370970f13d58f617379da64efb1f88a522f3f03 (patch)
tree1b4d44d5146b0decf8946155810308d5514bd695 /phpBB/phpbb/template/twig/lexer.php
parentda332aa0a5cbeabbcce5551ee955c701fc2a1d73 (diff)
downloadforums-6370970f13d58f617379da64efb1f88a522f3f03.tar
forums-6370970f13d58f617379da64efb1f88a522f3f03.tar.gz
forums-6370970f13d58f617379da64efb1f88a522f3f03.tar.bz2
forums-6370970f13d58f617379da64efb1f88a522f3f03.tar.xz
forums-6370970f13d58f617379da64efb1f88a522f3f03.zip
[ticket/11943] Split fix_inline_variable_tokens into 3 steps
DEFINE shouldn't add/remove surrounding quotes, but must have the inline variable tokens fixed PHPBB3-11943
Diffstat (limited to 'phpBB/phpbb/template/twig/lexer.php')
-rw-r--r--phpBB/phpbb/template/twig/lexer.php60
1 files changed, 50 insertions, 10 deletions
diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php
index efd6a0bd84..f4efc58540 100644
--- a/phpBB/phpbb/template/twig/lexer.php
+++ b/phpBB/phpbb/template/twig/lexer.php
@@ -68,8 +68,20 @@ class lexer extends \Twig_Lexer
);
// Fix tokens that may have inline variables (e.g. <!-- DEFINE $TEST = '{FOO}')
+ $code = $this->strip_surrounding_quotes(array(
+ 'INCLUDE',
+ 'INCLUDEPHP',
+ 'INCLUDEJS',
+ 'INCLUDECSS',
+ ), $code);
$code = $this->fix_inline_variable_tokens(array(
- //'DEFINE \$[a-zA-Z0-9_]+ =', // Disabling for ticket 11943
+ 'DEFINE \$[a-zA-Z0-9_]+ =',
+ 'INCLUDE',
+ 'INCLUDEPHP',
+ 'INCLUDEJS',
+ 'INCLUDECSS',
+ ), $code);
+ $code = $this->add_surrounding_quotes(array(
'INCLUDE',
'INCLUDEPHP',
'INCLUDEJS',
@@ -108,9 +120,29 @@ class lexer extends \Twig_Lexer
}
/**
+ * Strip surrounding quotes
+ *
+ * First step to fix tokens that may have inline variables
+ * E.g. <!-- INCLUDE '{TEST}.html' to <!-- INCLUDE {TEST}.html
+ *
+ * @param array $tokens array of tokens to search for (imploded to a regular expression)
+ * @param string $code
+ * @return string
+ */
+ protected function strip_surrounding_quotes($tokens, $code)
+ {
+ // Remove matching quotes at the beginning/end if a statement;
+ // E.g. 'asdf'"' -> asdf'"
+ // E.g. "asdf'"" -> asdf'"
+ // E.g. 'asdf'" -> 'asdf'"
+ return preg_replace('#<!-- (' . implode('|', $tokens) . ') (([\'"])?(.*?)\1) -->#', '<!-- $1 $2 -->', $code);
+ }
+
+ /**
* Fix tokens that may have inline variables
*
- * E.g. <!-- INCLUDE {TEST}.html
+ * Second step to fix tokens that may have inline variables
+ * E.g. <!-- INCLUDE '{TEST}.html' to <!-- INCLUDE ' ~ {TEST} ~ '.html
*
* @param array $tokens array of tokens to search for (imploded to a regular expression)
* @param string $code
@@ -120,23 +152,31 @@ class lexer extends \Twig_Lexer
{
$callback = function($matches)
{
- // 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]}' -->";
+ return "<!-- {$matches[1]} {$matches[2]} -->";
};
return preg_replace_callback('#<!-- (' . implode('|', $tokens) . ') (.+?) -->#', $callback, $code);
}
/**
+ * Add surrounding quotes
+ *
+ * Last step to fix tokens that may have inline variables
+ * E.g. <!-- INCLUDE '{TEST}.html' to <!-- INCLUDE '' ~ {TEST} ~ '.html'
+ *
+ * @param array $tokens array of tokens to search for (imploded to a regular expression)
+ * @param string $code
+ * @return string
+ */
+ protected function add_surrounding_quotes($tokens, $code)
+ {
+ return preg_replace('#<!-- (' . implode('|', $tokens) . ') (.+?) -->#', '<!-- $1 \'$2\' -->', $code);
+ }
+
+ /**
* Fix begin tokens (convert our BEGIN to Twig for)
*
* Not meant to be used outside of this context, public because the anonymous function calls this