diff --git a/src/AssetManager/Service/AssetManager.php b/src/AssetManager/Service/AssetManager.php index d9d6b094..c2d89fef 100644 --- a/src/AssetManager/Service/AssetManager.php +++ b/src/AssetManager/Service/AssetManager.php @@ -192,7 +192,7 @@ protected function resolve(RequestInterface $request) /* @var $uri \Laminas\Uri\UriInterface */ $uri = $request->getUri(); $fullPath = $uri->getPath(); - $path = substr($fullPath, strlen($request->getBasePath()) + 1); + $path = rawurldecode(substr($fullPath, strlen($request->getBasePath()) + 1)); $this->path = $path; $asset = $this->getResolver()->resolve($path); diff --git a/tests/AssetManagerTest/Service/AssetManagerTest.php b/tests/AssetManagerTest/Service/AssetManagerTest.php index 5370330d..e698365a 100644 --- a/tests/AssetManagerTest/Service/AssetManagerTest.php +++ b/tests/AssetManagerTest/Service/AssetManagerTest.php @@ -257,12 +257,12 @@ public function testSetExtensionFiltersNotDuplicate(): void $mimeResolver = new MimeResolver; $assetFilterManager->setMimeResolver($mimeResolver); $resolver->setAssetFilterManager($assetFilterManager); - + $response = new Response; $request = $this->getRequest(); // Have to change uri because asset-path would cause an infinite loop $request->setUri('http://localhost/base-path/blah.js'); - + $assetCacheManager = $this->getAssetCacheManagerMock(); $assetManager = new AssetManager($resolver->getAggregateResolver(), $config); $assetManager->setAssetCacheManager($assetCacheManager); @@ -505,6 +505,33 @@ public function testClearOutputBufferInSetAssetOnResponse(): void echo $response->getContent(); } + /** + * @dataProvider urlencodedDataProvider + */ + public function testUrlEncodedStringsWillBeDecoded(string $urlEncodedString, string $urlDecodedString): void + { + $resolver = $this->createMock(ResolverInterface::class); + $resolver + ->expects($this->once()) + ->method('resolve') + ->with($urlDecodedString); + + $request = new Request(); + $request->setUri('http://localhost/' . $urlEncodedString); + + $assetManager = new AssetManager($resolver); + $assetManager->resolvesToAsset($request); + } + + public function urlencodedDataProvider(): \Generator + { + yield ['sprite%402x.png', 'sprite@2x.png']; + yield ['some/folder/sprite%402x.png', 'some/folder/sprite@2x.png']; + + yield ['sprite@2x.png', 'sprite@2x.png']; + yield ['some/folder/sprite@2x.png', 'some/folder/sprite@2x.png']; + } + /** * @return string */