Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: urlencoded strings #229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AssetManager/Service/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
31 changes: 29 additions & 2 deletions tests/AssetManagerTest/Service/AssetManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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', '[email protected]'];
yield ['some/folder/sprite%402x.png', 'some/folder/[email protected]'];

yield ['[email protected]', '[email protected]'];
yield ['some/folder/[email protected]', 'some/folder/[email protected]'];
}

/**
* @return string
*/
Expand Down