Skip to content

Commit

Permalink
fix for fragment urls
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK committed Jun 12, 2019
1 parent eb6d223 commit 7b78ded
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/Resources/AbstractDispatchableResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,31 @@ protected function _getDispatchUrl($path): string
return $path;
}

list($newPath, $append) = Strings::explode('?', $path, [$path, null], 2);
$queryPos = strpos($path, '?');
$fragPos = strpos($path, '#');

if($queryPos + $fragPos > 0)
{
if($fragPos === false)
{
$appendChar = '?';
}
else if($queryPos === false)
{
$appendChar = '#';
}
else
{
$appendChar = min($queryPos, $fragPos) == $queryPos ? '?' : '#';
}
list($newPath, $append) = Strings::explode($appendChar, $path, [$path, null], 2);
$append = $append ? $appendChar . $append : null;
}
else
{
$append = '';
$newPath = $path;
}

$newPath = $this->_makeFullPath($newPath, dirname($this->_path));

Expand All @@ -137,7 +161,7 @@ protected function _getDispatchUrl($path): string
}
if(!empty($append))
{
$url .= '?' . $append;
$url .= $append;
}
return $url;
}
Expand Down
1 change: 1 addition & 0 deletions tests/DispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function testHandle()
$request = Request::create($uri);
$response = $dispatch->handleRequest($request);
$this->assertContains('font-size:14px', $response->getContent());
$this->assertContains('background:url(p/942e325b1780/img/test.svg#test)', $response->getContent());

$dispatch->addAlias('abc', 'resources/css');
$request = Request::create('/a/abc/bd04a611ed6d/test.css');
Expand Down
1 change: 1 addition & 0 deletions tests/_root/public/css/placeholder.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
body {
font-size: 14px;
background: url(../img/test.svg#test);
}
Empty file added tests/_root/public/img/test.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7b78ded

Please sign in to comment.