10000 Merge branch '2.8' into 3.2 · symfony/symfony@eb1e277 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb1e277

Browse files
Merge branch '2.8' into 3.2
* 2.8: [Asset] Fix invalid assets.xml Preventing the base path or absolute URL from being prefixed incorrectly on an absolute URL
2 parents 8a8d92d + 1bee0ad commit eb1e277

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
<service id="assets.path_package" class="Symfony\Component\Asset\PathPackage" abstract="true">
2323
<argument /> <!-- base path -->
24-
<argument type="service" /> <!-- version strategy -->
24+
<argument /> <!-- version strategy -->
2525
<argument type="service" id="assets.context" />
2626
</service>
2727

2828
<service id="assets.url_package" class="Symfony\Component\Asset\UrlPackage" abstract="true">
2929
<argument /> <!-- base URLs -->
30-
<argument type="service" /> <!-- version strategy -->
30+
<argument /> <!-- version strategy -->
3131
<argument type="service" id="assets.context" />
3232
</service>
3333

src/Symfony/Component/Asset/PathPackage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ public function getUrl($path)
5757
return $path;
5858
}
5959

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

6369
/**

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

Lines 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

Lines 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

Lines 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