Skip to content

Commit c669b88

Browse files
committed
bug symfony#22528 [Asset] Starting slash should indicate no basePath wanted (weaverryan)
This PR was squashed before being merged into the 2.7 branch (closes symfony#22528). Discussion ---------- [Asset] Starting slash should indicate no basePath wanted | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes-ish... and no-ish | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a **Important** View the second commit for an accurate diff. The first commit just renames some strings in a test for clarity. When we moved `PathPackage` from `Templating` to `Asset`, we actually changed its behavior. Assume that we're deployed under a `/subdir` subdirectory: **Before** `{{ asset('/main.css') }}` would *not* have the base path prefixed -> `/main.css` **After** `{{ asset('/main.css') }}` *does* have the base path prefixed -> `/subdir/main.css` https://github.com/symfony/symfony/blob/3adff11d729ccdfc4eb4b189417ec04491c6eaad/src/Symfony/Component/Templating/Asset/PathPackage.php#L61-L63 This PR simply reverses that, to the *previous* behavior. This *is* a BC break... and also arguably a bug fix :). Interestingly, when we changed the behavior the first time (i.e. broke BC), I don't think that anyone noticed. It should only affect users deployed under a subdirectory. Why do I care? I'm using the new `JsonManifestVersionStrategy` with a library that is outputting paths that *already* include my subdirectory: ```json { "build/main.css": "/subdir/build/main.abc123.css" } ``` So, I do not want Symfony to detect the `/subdir` and apply it a second time. Commits ------- 3cc096b [Asset] Starting slash should indicate no basePath wanted
2 parents af15ead + 3cc096b commit c669b88

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/Symfony/Component/Asset/PathPackage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function getUrl($path)
5858

5959
$versionedPath = $this->getVersionStrategy()->applyVersion($path);
6060

61-
if ($this->isAbsoluteUrl($versionedPath)) {
61+
// if absolute or begins with /, we're done
62+
if ($this->isAbsoluteUrl($versionedPath) || ($versionedPath && '/' === $versionedPath[0])) {
6263
return $versionedPath;
6364
}
6465

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public function getConfigs()
3535

3636
array('', '', '/foo', '/foo?v1'),
3737

38-
array('/foo', '', '/foo', '/foo/foo?v1'),
39-
array('/foo', '', 'foo', '/foo/foo?v1'),
40-
array('foo', '', 'foo', '/foo/foo?v1'),
41-
array('foo/', '', 'foo', '/foo/foo?v1'),
42-
array('/foo/', '', 'foo', '/foo/foo?v1'),
43-
44-
array('/foo', 'version-%2$s/%1$s', '/foo', '/foo/version-v1/foo'),
45-
array('/foo', 'version-%2$s/%1$s', 'foo', '/foo/version-v1/foo'),
46-
array('/foo', 'version-%2$s/%1$s', 'foo/', '/foo/version-v1/foo/'),
47-
array('/foo', 'version-%2$s/%1$s', '/foo/', '/foo/version-v1/foo/'),
38+
array('/foo', '', '/bar', '/bar?v1'),
39+
array('/foo', '', 'bar', '/foo/bar?v1'),
40+
array('foo', '', 'bar', '/foo/bar?v1'),
41+
array('foo/', '', 'bar', '/foo/bar?v1'),
42+
array('/foo/', '', 'bar', '/foo/bar?v1'),
43+
44+
array('/foo', 'version-%2$s/%1$s', '/bar', '/version-v1/bar'),
45+
array('/foo', 'version-%2$s/%1$s', 'bar', '/foo/version-v1/bar'),
46+
array('/foo', 'version-%2$s/%1$s', 'bar/', '/foo/version-v1/bar/'),
47+
array('/foo', 'version-%2$s/%1$s', '/bar/', '/version-v1/bar/'),
4848
);
4949
}
5050

@@ -61,17 +61,17 @@ public function testGetUrlWithContext($basePathRequest, $basePath, $format, $pat
6161
public function getContextConfigs()
6262
{
6363
return array(
64-
array('', '/foo', '', '/foo', '/foo/foo?v1'),
65-
array('', '/foo', '', 'foo', '/foo/foo?v1'),
66-
array('', 'foo', '', 'foo', '/foo/foo?v1'),
67-
array('', 'foo/', '', 'foo', '/foo/foo?v1'),
68-
array('', '/foo/', '', 'foo', '/foo/foo?v1'),
69-
70-
array('/bar', '/foo', '', '/foo', '/bar/foo/foo?v1'),
71-
array('/bar', '/foo', '', 'foo', '/bar/foo/foo?v1'),
72-
array('/bar', 'foo', '', 'foo', '/bar/foo/foo?v1'),
73-
array('/bar', 'foo/', '', 'foo', '/bar/foo/foo?v1'),
74-
array('/bar', '/foo/', '', 'foo', '/bar/foo/foo?v1'),
64+
array('', '/foo', '', '/baz', '/baz?v1'),
65+
array('', '/foo', '', 'baz', '/foo/baz?v1'),
66+
array('', 'foo', '', 'baz', '/foo/baz?v1'),
67+
array('', 'foo/', '', 'baz', '/foo/baz?v1'),
68+
array('', '/foo/', '', 'baz', '/foo/baz?v1'),
69+
70+
array('/bar', '/foo', '', '/baz', '/baz?v1'),
71+
array('/bar', '/foo', '', 'baz', '/bar/foo/baz?v1'),
72+
array('/bar', 'foo', '', 'baz', '/bar/foo/baz?v1'),
73+
array('/bar', 'foo/', '', 'baz', '/bar/foo/baz?v1'),
74+
array('/bar', '/foo/', '', 'baz', '/bar/foo/baz?v1'),
7575
);
7676
}
7777

0 commit comments

Comments
 (0)