Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 746c91e

Browse filesBrowse files
committed
Preventing the base path or absolute URL from being prefixed incorrectly on an absolute URL
If the version strategy returns an absolute URL, that should be the final URL.
1 parent 5742958 commit 746c91e
Copy full SHA for 746c91e

File tree

Expand file treeCollapse file tree

4 files changed

+33
-1
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+33
-1
lines changed

‎src/Symfony/Component/Asset/PathPackage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Asset/PathPackage.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ public function getUrl($path)
5656
return $path;
5757
}
5858

59-
return $this->getBasePath().ltrim($this->getVersionStrategy()->applyVersion($path), '/');
59+
$versionedPath = $this->getVersionStrategy()->applyVersion($path);
60+
61+
if ($this->isAbsoluteUrl($versionedPath)) {
62+
return $versionedPath;
63+
}
64+
65+
return $this->getBasePath().ltrim($versionedPath, '/');
6066
}
6167

6268
/**

‎src/Symfony/Component/Asset/Tests/PathPackageTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Asset/Tests/PathPackageTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ public function getContextConfigs()
7575
);
7676
}
7777

78+
public function testVersionStrategyGivesAbsoluteURL()
79+
{
80+
$versionStrategy = $this->getMockBuilder('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface')->getMock();
81+
$versionStrategy->expects($this->any())
82+
->method('applyVersion')
83+
->willReturn('https://cdn.com/bar/main.css');
84+
$package = new PathPackage('/subdirectory', $versionStrategy, $this->getContext('/bar'));
85+
86+
$this->assertEquals('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
87+
}
88+
7889
private function getContext($basePath)
7990
{
8091
$context = $this->getMockBuilder('Symfony\Component\Asset\Context\ContextInterface')->getMock();

‎src/Symfony/Component/Asset/Tests/UrlPackageTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Asset/Tests/UrlPackageTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ public function getContextConfigs()
7777
);
7878
}
7979

80+
public function testVersionStrategyGivesAbsoluteURL()
81+
{
82+
$versionStrategy = $this->getMockBuilder('Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface')->getMock();
83+
$versionStrategy->expects($this->any())
84+
->method('applyVersion')
85+
->willReturn('https://cdn.com/bar/main.css');
86+
$package = new UrlPackage('https://example.com', $versionStrategy);
87+
88+
$this->assertEquals('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
89+
}
90+
8091
/**
8192
* @expectedException \Symfony\Component\Asset\Exception\LogicException
8293
*/

‎src/Symfony/Component/Asset/UrlPackage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Asset/UrlPackage.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function getUrl($path)
8181

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

84+
if ($this->isAbsoluteUrl($url)) {
85+
return $url;
86+
}
87+
8488
if ($url && '/' != $url[0]) {
8589
$url = '/'.$url;
8690
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.