switch ($token) {
case $this->options['tag_comment'][0]:
- $commentEndRegex = '/.*?(?:'.preg_quote($this->options['whitespace_trim'], '/')
- .preg_quote($this->options['tag_comment'][1], '/').'\s*|'
- .preg_quote($this->options['tag_comment'][1], '/').')\n?/As';
-
- if (!preg_match($commentEndRegex, $this->code, $match, null, $this->cursor)) {
- throw new Twig_Error_Syntax('Unclosed comment', $this->lineno, $this->filename);
- }
-
- $this->moveCursor($match[0]);
+ $this->lexComment();
break;
case $this->options['tag_block'][0]:
$this->moveCursor($text.$match[0][0]);
}
+ protected function lexComment()
+ {
+ $commentEndRegex = '/(?:'.preg_quote($this->options['whitespace_trim'], '/')
+ .preg_quote($this->options['tag_comment'][1], '/').'\s*|'
+ .preg_quote($this->options['tag_comment'][1], '/').')\n?/s';
+
+ if (!preg_match($commentEndRegex, $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
+ throw new Twig_Error_Syntax('Unclosed comment', $this->lineno, $this->filename);
+ }
+
+ $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]);
+ }
+
protected function pushToken($type, $value = '')
{
// do not push empty text tokens
// baz
$this->assertSame(11, $stream->expect(Twig_Token::NAME_TYPE)->getLine());
}
+
+ public function testLongComments()
+ {
+ $template = '{# '.str_repeat('*', 100000).' #}';
+
+ $lexer = new Twig_Lexer(new Twig_Environment());
+ $lexer->tokenize($template);
+
+ // should not throw an exception
+ }
+
+ public function testLongRaw()
+ {
+ $template = '{% raw %}'.str_repeat('*', 100000).'{% endraw %}';
+
+ $lexer = new Twig_Lexer(new Twig_Environment());
+ $stream = $lexer->tokenize($template);
+
+ // should not throw an exception
+ }
+
+ public function testLongBlock()
+ {
+ $template = '{{ '.str_repeat('*', 100000).' }}';
+
+ $lexer = new Twig_Lexer(new Twig_Environment());
+ $stream = $lexer->tokenize($template);
+
+ // should not throw an exception
+ }
+
+ public function testLongBlock1()
+ {
+ $template = '{% '.str_repeat('*', 100000).' %}';
+
+ $lexer = new Twig_Lexer(new Twig_Environment());
+ $stream = $lexer->tokenize($template);
+
+ // should not throw an exception
+ }
}