Fix #20087: Add custom attributes to script tags

This commit is contained in:
skepticspriggan
2024-04-03 15:18:16 +02:00
committed by GitHub
parent f7cba1b9de
commit bf3ada13fc
4 changed files with 26 additions and 0 deletions

View File

@ -90,6 +90,21 @@ class HtmlTest extends TestCase
$this->assertEquals("<script type=\"text/js\">{$content}</script>", Html::script($content, ['type' => 'text/js']));
}
public function testScriptCustomAttribute()
{
$nonce = Yii::$app->security->generateRandomString();
$this->mockApplication([
'components' => [
'view' => [
'class' => 'yii\web\View',
'scriptOptions' => ['nonce' => $nonce],
],
],
]);
$content = 'a <>';
$this->assertEquals("<script nonce=\"{$nonce}\">{$content}</script>", Html::script($content));
}
public function testCssFile()
{
$this->assertEquals('<link href="http://example.com" rel="stylesheet">', Html::cssFile('http://example.com'));