Commit e6d5af03 by Alexander Makarov

Merge pull request #3878 from dapatrese/3877-twig-lexer-options-exception

Fixes Twig lexerOptions throwing exception (#3877)
parents 210a8e9a 48f941da
......@@ -104,11 +104,6 @@ class ViewRenderer extends BaseViewRenderer
$this->addExtensions($this->extensions);
}
// Change lexer syntax
if (!empty($this->lexerOptions)) {
$this->setLexerOptions($this->lexerOptions);
}
// Adding global 'void' function (usage: {{void(App.clientScript.registerScriptFile(...))}})
$this->twig->addFunction('void', new \Twig_Function_Function(function ($argument) {
}));
......@@ -130,6 +125,11 @@ class ViewRenderer extends BaseViewRenderer
}));
$this->twig->addGlobal('app', \Yii::$app);
// Change lexer syntax (must be set after other settings)
if (!empty($this->lexerOptions)) {
$this->setLexerOptions($this->lexerOptions);
}
}
/**
......
......@@ -54,6 +54,7 @@ Yii Framework 2 Change Log
- Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark)
- Bug: URL encoding for the route parameter added to `\yii\web\UrlManager` (klimov-paul)
- Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
- Bug #3877 : Fixed Twig lexerOptions throwing exception
- Enh #2264: `CookieCollection::has()` will return false for expired or removed cookies (qiangxue)
- Enh #2435: `yii\db\IntegrityException` is now thrown on database integrity errors instead of general `yii\db\Exception` (samdark)
- Enh #2837: Error page now shows arguments in stack trace method calls (samdark)
......
......@@ -35,6 +35,18 @@ class ViewRendererTest extends TestCase
$this->assertEquals(1, preg_match('#<script src="/assets/[0-9a-z]+/jquery\\.js"></script>\s*</body>#', $content), 'content does not contain the jquery js:' . $content);
}
/**
* https://github.com/yiisoft/yii2/issues/3877
*/
public function testLexerOptions()
{
$view = $this->mockView();
$content = $view->renderFile('@yiiunit/extensions/twig/views/layout.twig');
$this->assertFalse(strpos($content, 'CUSTOM_LEXER_TWIG_COMMENT') , 'custom comment lexerOption is not applied');
$this->assertTrue(0 < strpos($content, 'DEFAULT_TWIG_COMMENT') , 'default comment style not modified via lexerOptions');
}
protected function mockView()
{
return new View([
......@@ -52,6 +64,9 @@ class ViewRendererTest extends TestCase
'functions' => [
't' => '\Yii::t',
'json_encode' => '\yii\helpers\Json::encode'
],
'lexerOptions' => [
'tag_comment' => [ '{*', '*}' ],
]
],
],
......
......@@ -8,6 +8,8 @@
</head>
<body>
{{ this.beginBody() }}
{# DEFAULT_TWIG_COMMENT #}
{* CUSTOM_LEXER_TWIG_COMMENT *}
body
{{ this.endBody() }}
</body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment