Skip to content

Commit

Permalink
Fix static caching error when using urls without slashes (#7130)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <[email protected]>
  • Loading branch information
arthurperton and jasonvarga authored Nov 28, 2022
1 parent e1c9499 commit ca51cbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/StaticCaching/Cachers/AbstractCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ public function hasCachedPage(Request $request)

protected function getPathAndDomain($url)
{
if (Str::startsWith($url, '/')) {
$parsed = parse_url($url);

if (! isset($parsed['scheme'])) {
return [
$url,
Str::ensureLeft($url, '/'),
$this->getBaseUrl(),
];
}

$parsed = parse_url($url);

$query = isset($parsed['query']) ? '?'.$parsed['query'] : '';

$path = $parsed['path'] ?? '/';
Expand Down
6 changes: 4 additions & 2 deletions tests/StaticCaching/CacherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,20 @@ public function it_invalidates_urls()
$cacher = $this->cacher();

$cacher->shouldReceive('invalidateUrl')->once()->with('/', 'http://example.com');
$cacher->shouldReceive('invalidateUrl')->once()->with('/one', 'http://example.com');
$cacher->shouldReceive('invalidateUrl')->twice()->with('/one', 'http://example.com');
$cacher->shouldReceive('invalidateUrl')->once()->with('/two', 'http://example.com');
$cacher->shouldReceive('invalidateUrl')->once()->with('/three', 'http://example.co.uk');
$cacher->shouldReceive('invalidateUrl')->times(2)->with('/blog/post', 'http://example.com');
$cacher->shouldReceive('invalidateUrl')->times(3)->with('/blog/post', 'http://example.com');
$cacher->shouldReceive('invalidateUrl')->once()->with('/blog/post', 'http://example.co.uk');

$cacher->invalidateUrls([
'/',
'/one',
'one',
'http://example.com/two',
'http://example.co.uk/three',
'/blog/*',
'blog/*',
'http://example.com/blog/*',
'http://example.co.uk/blog/*',
]);
Expand Down

0 comments on commit ca51cbc

Please sign in to comment.