Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 44051bd

Browse filesBrowse files
bug #53260 [AssetMapper] Handle assets with non-ascii characters in dev server (fbourigault)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [AssetMapper] Handle assets with non-ascii characters in dev server | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | n/a | License | MIT In `AssetMapperDevServerSubscriber`, `$event->getRequest()->getPathInfo()` is used to get the path of the asset to serve. As `Request::getPathInfo()` returns the raw path, if the requested asset contains non-ascii characters in it's path, a 404 is returned instead of the asset because of the encoded path info. Using `rawurldecode` enabled handling of encoded paths. I just pushed the use of the `rawurldecode` for now as don't known how to test this properly. I tried renaming `dir1/file1.css` to `dir1/file 1.css` or creating a new `and voilà.css` but both approches affect many other tests. How could I test this properly? Commits ------- 27e3d2b [AssetMapper] Handle assets with non-ascii characters in dev server
2 parents 8d8c8fe + 27e3d2b commit 44051bd
Copy full SHA for 44051bd

File tree

Expand file treeCollapse file tree

5 files changed

+20
-3
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+20
-3
lines changed

‎src/Symfony/Component/AssetMapper/AssetMapperDevServerSubscriber.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/AssetMapperDevServerSubscriber.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function onKernelRequest(RequestEvent $event): void
117117
return;
118118
}
119119

120-
$pathInfo = $event->getRequest()->getPathInfo();
120+
$pathInfo = rawurldecode($event->getRequest()->getPathInfo());
121121
if (!str_starts_with($pathInfo, $this->publicPrefix)) {
122122
return;
123123
}

‎src/Symfony/Component/AssetMapper/Tests/AssetMapperDevServerSubscriberFunctionalTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/Tests/AssetMapperDevServerSubscriberFunctionalTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ public function testGettingAssetWorks()
3232
$this->assertSame('immutable, max-age=604800, public', $response->headers->get('Cache-Control'));
3333
}
3434

35+
public function testGettingAssetWithNonAsciiFilenameWorks()
36+
{
37+
$client = static::createClient();
38+
39+
$client->request('GET', '/assets/voilà-6344422da690fcc471f23f7a8966cd1c.css');
40+
$response = $client->getResponse();
41+
$this->assertSame(200, $response->getStatusCode());
42+
$this->assertSame(<<<EOF
43+
/* voilà.css */
44+
body {}
45+
46+
EOF, $response->getContent());
47+
}
48+
3549
public function test404OnUnknownAsset()
3650
{
3751
$client = static::createClient();

‎src/Symfony/Component/AssetMapper/Tests/Command/AssetsMapperCompileCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/Tests/Command/AssetsMapperCompileCommandTest.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testAssetsAreCompiled()
6363

6464
$finder = new Finder();
6565
$finder->in($targetBuildDir)->files();
66-
$this->assertCount(10, $finder);
66+
$this->assertCount(11, $finder);
6767
$this->assertFileExists($targetBuildDir.'/manifest.json');
6868

6969
$this->assertSame([
@@ -74,6 +74,7 @@ public function testAssetsAreCompiled()
7474
'file4.js',
7575
'subdir/file5.js',
7676
'subdir/file6.js',
77+
'voilà.css',
7778
], array_keys(json_decode(file_get_contents($targetBuildDir.'/manifest.json'), true)));
7879

7980
$this->assertFileExists($targetBuildDir.'/importmap.json');

‎src/Symfony/Component/AssetMapper/Tests/fixtures/AssetMapperTestAppKernel.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/Tests/fixtures/AssetMapperTestAppKernel.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
4040
'http_client' => true,
4141
'assets' => null,
4242
'asset_mapper' => [
43-
'paths' => ['dir1', 'dir2'],
43+
'paths' => ['dir1', 'dir2', 'non_ascii'],
4444
],
4545
'test' => true,
4646
]);
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* voilà.css */
2+
body {}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.