8000 Fix unable to use asset mapper with CSP · symfony/symfony@0a0a2c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a0a2c9

Browse files
committed
Fix unable to use asset mapper with CSP
1 parent e1bf69c commit 0a0a2c9

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Symfony/Bridge/Twig/Extension/ImportMapRuntime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function __construct(private readonly ImportMapRenderer $importMapRendere
2222
{
2323
}
2424

25-
public function importmap(?string $entryPoint = 'app'): string
25+
public function importmap(?string $entryPoint = 'app', array $attributes = []): string
2626
{
27-
return $this->importMapRenderer->render($entryPoint);
27+
return $this->importMapRenderer->render($entryPoint, $attributes);
2828
}
2929
}

src/Symfony/Component/AssetMapper/ImportMap/ImportMapRenderer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ public function __construct(
2929
) {
3030
}
3131

32-
public function render(string $entryPoint = null): string
32+
public function render(string $entryPoint = null, array $attributes = []): string
3333
{
3434
$attributeString = '';
3535

36-
if (isset($this->scriptAttributes['src']) || isset($this->scriptAttributes['type'])) {
36+
$attributes += $this->scriptAttributes;
37+
if (isset($attributes['src']) || isset($attributes['type'])) {
3738
throw new \InvalidArgumentException(sprintf('The "src" and "type" attributes are not allowed on the <script> tag rendered by "%s".', self::class));
3839
}
3940

40-
foreach ($this->scriptAttributes as $name => $value) {
41+
foreach ($attributes as $name => $value) {
4142
$attributeString .= ' ';
4243
if (true === $value) {
4344
$attributeString .= $name;
@@ -70,7 +71,7 @@ public function render(string $entryPoint = null): string
7071
}
7172

7273
if (null !== $entryPoint) {
73-
$output .= "\n<script type=\"module\">import '".str_replace("'", "\\'", $entryPoint)."';</script>";
74+
$output .= "\n<script type=\"module\"$attributeString>import '".str_replace("'", "\\'", $entryPoint)."';</script>";
7475
}
7576

7677
return $output;

0 commit comments

Comments
 (0)
0