Skip to content

Commit f206dfd

Browse files
committed
bug #13745 Fixed absolute_url for absolute paths (florianv)
This PR was merged into the 2.7 branch. Discussion ---------- Fixed absolute_url for absolute paths | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#13724 | License | MIT The issue is that `asset()` and `absolute_url()` cannot be composed because `asset()` already returns an absolute path (using the `PathPackage`) and `absolute_url()` still prepends the base path. So the resulting url contains the base path twice. So this PR removes appending the base path to absolute paths (starting with `/`) passed to `absolute_url()`. Commits ------- 08aa7bc Fixed absolute_url for absolute paths
2 parents 65e4a5a + 08aa7bc commit f206dfd

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Symfony/Bridge/Twig/Extension/HttpFoundationExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public function generateAbsoluteUrl($path)
6767
$prefix = substr($prefix, 0, $pos).'/';
6868
}
6969

70-
$path = $prefix.$path;
70+
return $request->getUriForPath($prefix.$path);
7171
}
7272

73-
return $request->getUriForPath($path);
73+
return $request->getSchemeAndHttpHost().$path;
7474
}
7575

7676
/**

src/Symfony/Bridge/Twig/Tests/Extension/HttpFoundationExtensionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ public function getGenerateAbsoluteUrlData()
4343
);
4444
}
4545

46+
public function testGenerateAbsoluteUrlWithScriptFileName()
47+
{
48+
$request = Request::create('http://localhost/app/web/app_dev.php');
49+
$request->server->set('SCRIPT_FILENAME', '/var/www/app/web/app_dev.php');
50+
51+
$stack = new RequestStack();
52+
$stack->push($request);
53+
$extension = new HttpFoundationExtension($stack);
54+
55+
$this->assertEquals(
56+
'http://localhost/app/web/bundles/framework/css/structure.css',
57+
$extension->generateAbsoluteUrl('/app/web/bundles/framework/css/structure.css')
58+
);
59+
}
60+
4661
/**
4762
* @dataProvider getGenerateRelativePathData()
4863
*/

0 commit comments

Comments
 (0)