Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
Preventing the base path or absolute URL from being prefixed incorrec…
…tly on an absolute URL

If the version strategy returns an absolute URL, that should be the final URL.
  • Loading branch information
weaverryan committed Apr 26, 2017
commit 746c91eea42ee4799b6ffeb2b4aada531e430b47
8 changes: 7 additions & 1 deletion src/Symfony/Component/Asset/PathPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public function getUrl($path)
return $path;
}

return $this->getBasePath().ltrim($this->getVersionStrategy()->applyVersion($path), '/');
$versionedPath = $this->getVersionStrategy()->applyVersion($path);

if ($this->isAbsoluteUrl($versionedPath)) {
return $versionedPath;
}

return $this->getBasePath().ltrim($versionedPath, '/');
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Asset/Tests/PathPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ public function getContextConfigs()
);
}

public function testVersionStrategyGivesAbsoluteURL()
{
$versionStrategy = $this->getMockBuilder('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface')->getMock();
$versionStrategy->expects($this->any())
->method('applyVersion')
->willReturn('https://cdn.com/bar/main.css');
$package = new PathPackage('/subdirectory', $versionStrategy, $this->getContext('/bar'));

$this->assertEquals('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
}

private function getContext($basePath)
{
$context = $this->getMockBuilder('Symfony\Component\Asset\Context\ContextInterface')->getMock();
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Asset/Tests/UrlPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ public function getContextConfigs()
);
}

public function testVersionStrategyGivesAbsoluteURL()
{
$versionStrategy = $this->getMockBuilder('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface')->getMock();
$versionStrategy->expects($this->any())
->method('applyVersion')
->willReturn('https://cdn.com/bar/main.css');
$package = new UrlPackage('https://example.com', $versionStrategy);

$this->assertEquals('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
}

/**
* @expectedException \Symfony\Component\Asset\Exception\LogicException
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Asset/UrlPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function getUrl($path)

$url = $this->getVersionStrategy()->applyVersion($path);

if ($this->isAbsoluteUrl($url)) {
return $url;
}

if ($url && '/' != $url[0]) {
$url = '/'.$url;
}
Expand Down