浏览代码

[Templating] updated assets helper to leave protocol-relative URLs untouched

Kris Wallsmith 14 年之前
父节点
当前提交
55671be888

+ 1 - 1
src/Symfony/Component/Templating/Helper/AssetsHelper.php

@@ -146,7 +146,7 @@ class AssetsHelper extends Helper implements AssetPackageInterface
      */
     public function getUrl($path, $packageName = null)
     {
-        if (false !== strpos($path, '://')) {
+        if (false !== strpos($path, '://') || 0 === strpos($path, '//')) {
             return $path;
         }
 

+ 6 - 0
tests/Symfony/Tests/Component/Templating/Helper/AssetsHelperTest.php

@@ -74,4 +74,10 @@ class AssetsHelperTest extends \PHPUnit_Framework_TestCase
         $helper = new AssetsHelper('/bar', 'http://www.example.com/foo', 'abcd');
         $this->assertEquals('http://www.example.com/foo/foo.js?abcd', $helper->getUrl('foo.js'), '->getUrl() appends the version if defined');
     }
+
+    public function testGetUrlLeavesProtocolRelativePathsUntouched()
+    {
+        $helper = new AssetsHelper(null, 'http://foo.com');
+        $this->assertEquals('//bar.com/asset', $helper->getUrl('//bar.com/asset'));
+    }
 }