Skip to content

Commit f26a5c2

Browse files
committed
minor symfony#59313 [AssetMapper] add leading slash to public prefix (IndraGunawan)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [AssetMapper] add leading slash to public prefix | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT ```yaml framework: asset_mapper: public_prefix: custom/path ``` i added above config to make `asset-map:compile` command create all files in that directory but i was not aware if that value should start with a `/` and make the page not load properly, so if the `/` is required then we can add it by default instead Commits ------- e3a7331 [AssetMapper] add leading slash to public prefix
2 parents 70caa73 + e3a7331 commit f26a5c2

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)