Skip to content

Commit e3a7331

Browse files
IndraGunawanfabpot
authored andcommitted
[AssetMapper] add leading slash to public prefix
1 parent 96941db commit e3a7331

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

src/Symfony/Component/AssetMapper/AssetMapperDevServerSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function __construct(
109109
private readonly ?CacheItemPoolInterface $cacheMapCache = null,
110110
private readonly ?Profiler $profiler = null,
111111
) {
112-
$this->publicPrefix = rtrim($publicPrefix, '/').'/';
112+
$this->publicPrefix = '/'.trim($publicPrefix, '/').'/';
113113
$this->extensionsMap = array_merge(self::EXTENSIONS_MAP, $extensionsMap);
114114
}
115115

src/Symfony/Component/AssetMapper/Path/PublicAssetsPathResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class PublicAssetsPathResolver implements PublicAssetsPathResolverInterface
1818
public function __construct(
1919
string $publicPrefix = '/assets/',
2020
) {
21-
// ensure that the public prefix always ends with a single slash
22-
$this->publicPrefix = rtrim($publicPrefix, '/').'/';
21+
// ensure that the public prefix always starts and ends with a single slash
22+
$this->publicPrefix = '/'.trim($publicPrefix, '/').'/';
2323
}
2424

2525
public function resolvePublicPath(string $logicalPath): string

src/Symfony/Component/AssetMapper/Tests/Fixtures/AssetMapperTestAppKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
4444
'assets' => null,
4545
'asset_mapper' => [
4646
'paths' => ['dir1', 'dir2', 'non_ascii', 'assets'],
47+
'public_prefix' => 'assets'
4748
],
4849
'test' => true,
4950
]);

src/Symfony/Component/AssetMapper/Tests/Path/PublicAssetsPathResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testResolvePublicPath()
2626
$this->assertSame('/assets-prefix/foo/bar', $resolver->resolvePublicPath('foo/bar'));
2727

2828
$resolver = new PublicAssetsPathResolver(
29-
'/assets-prefix', // The trailing slash should be added automatically
29+
'assets-prefix', // The leading and trailing slash should be added automatically
3030
);
3131
$this->assertSame('/assets-prefix/', $resolver->resolvePublicPath(''));
3232
$this->assertSame('/assets-prefix/foo/bar', $resolver->resolvePublicPath('/foo/bar'));

0 commit comments

Comments
 (0)