Skip to content
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
5 changes: 5 additions & 0 deletions Templating/LazyFilterRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public function filterCache(string $path, string $filter, array $config = [], ?s

private function cleanPath(string $path): string
{
// strip absolute URLs (e.g. remote filesystems like S3) to their path, but leave local paths with "?" or "#" untouched
if (null !== parse_url($path, PHP_URL_HOST)) {
$path = parse_url($path, PHP_URL_PATH) ?? $path;
}

if (!$this->assetVersion && !$this->jsonManifest) {
return $path;
}
Expand Down
31 changes: 24 additions & 7 deletions Tests/Templating/LazyFilterRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,23 @@ protected function setUp(): void

public function provideImageNames(): iterable
{
yield 'regular' => ['image' => 'cats.jpeg', 'urlimage' => 'cats.jpeg'];
yield 'whitespace' => ['image' => 'white cat.jpeg', 'urlimage' => 'white%20cat.jpeg'];
yield 'plus' => ['image' => 'cat+plus.jpeg', 'urlimage' => 'cat%2Bplus.jpeg'];
yield 'questionmark' => ['image' => 'cat?question.jpeg', 'urlimage' => 'cat%3Fquestion.jpeg'];
yield 'hash' => ['image' => 'cat#hash.jpeg', 'urlimage' => 'cat%23hash.jpeg'];
yield 'regular' => ['image' => 'cats.jpeg', 'callingimage' => 'cats.jpeg', 'urlimage' => 'cats.jpeg'];
yield 'whitespace' => ['image' => 'white cat.jpeg', 'callingimage' => 'white cat.jpeg', 'urlimage' => 'white%20cat.jpeg'];
yield 'plus' => ['image' => 'cat+plus.jpeg', 'callingimage' => 'cat+plus.jpeg', 'urlimage' => 'cat%2Bplus.jpeg'];
yield 'questionmark' => ['image' => 'cat?question.jpeg', 'callingimage' => 'cat?question.jpeg', 'urlimage' => 'cat%3Fquestion.jpeg'];
yield 'hash' => ['image' => 'cat#hash.jpeg', 'callingimage' => 'cat#hash.jpeg', 'urlimage' => 'cat%23hash.jpeg'];
yield 'absolute url' => ['image' => 'https://www.example.org/images/dogs.jpg', 'callingimage' => '/images/dogs.jpg', 'urlimage' => '/media/cache/thumbnail/images/dogs.jpg'];
}

/**
* @dataProvider provideImageNames
*/
public function testInvokeFilterMethod($image, $urlimage): void
public function testInvokeFilterMethod($image, $callingimage, $urlimage): void
{
$this->manager
->expects($this->once())
->method('getBrowserPath')
->with($image, self::FILTER)
->with($callingimage, self::FILTER)
->willReturn($urlimage);

$actualPath = $this->runtime->filter($image, self::FILTER);
Expand Down Expand Up @@ -187,6 +188,22 @@ public function testInvokeFilterCacheMethod(): void
$this->assertSame($expectedCachePath, $actualPath);
}

public function testInvokeFilterCacheMethodWithAbsoluteUrl(): void
{
$expectedInputPath = '/images/dogs.jpg';
$expectedCachePath = '/media/cache/thumbnail/images/dogs.jpg';

$this->manager
->expects($this->once())
->method('resolve')
->with($expectedInputPath, self::FILTER)
->willReturn($expectedCachePath);

$actualPath = $this->runtime->filterCache('https://www.example.org/images/dogs.jpg', self::FILTER);

$this->assertSame($expectedCachePath, $actualPath);
}

public function testInvokeFilterCacheMethodWithRuntimeConfig(): void
{
$expectedInputPath = 'thePathToTheImage';
Expand Down