Skip to content

Commit

Permalink
Merge pull request #171 from jasonvarga/master
Browse files Browse the repository at this point in the history
Fix source being trimmed when it begins with the baseUrl
  • Loading branch information
reinink authored Jan 19, 2017
2 parents fef5073 + 49de68e commit eded0a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ public function getSourcePathPrefix()
public function getSourcePath($path)
{
$path = trim($path, '/');

$baseUrl = $this->baseUrl.'/';

if (substr($path, 0, strlen($this->baseUrl)) === $this->baseUrl) {
$path = trim(substr($path, strlen($this->baseUrl)), '/');
if (substr($path, 0, strlen($baseUrl)) === $baseUrl) {
$path = trim(substr($path, strlen($baseUrl)), '/');
}

if ($path === '') {
Expand Down
10 changes: 10 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ public function testGetSourcePathWithPrefix()
$this->assertEquals('img/image.jpg', $this->server->getSourcePath('image.jpg'));
}

public function testGetsSourcePathWithBaseUrl()
{
$this->server->setBaseUrl('img/');
$this->assertEquals('image.jpg', $this->server->getSourcePath('image.jpg'));

// Test for a bug where if the path starts with the same substring as the base url, the source
// path would trim the base url off the filename. eg, the following would've returned 'ur.jpg'
$this->assertEquals('imgur.jpg', $this->server->getSourcePath('imgur.jpg'));
}

public function testGetSourcePathWithMissingPath()
{
$this->setExpectedException(
Expand Down

0 comments on commit eded0a9

Please sign in to comment.