From ebb1601d5de2f782769b297642727649577bac07 Mon Sep 17 00:00:00 2001 From: Sergey Shevchenko Date: Fri, 5 Aug 2022 15:34:59 +1200 Subject: [PATCH] fix: misc suggested changes * disable resolve_relative_css_refs by default * variable naming * using proper path joiner * test comment typo --- src/View/Requirements_Backend.php | 6 +++--- tests/php/View/RequirementsTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/View/Requirements_Backend.php b/src/View/Requirements_Backend.php index d0bde0851..1316ae123 100644 --- a/src/View/Requirements_Backend.php +++ b/src/View/Requirements_Backend.php @@ -65,7 +65,7 @@ class Requirements_Backend * @config * @var bool */ - private static $resolve_relative_css_refs = true; + private static $resolve_relative_css_refs = false; /** * Paths to all required JavaScript files relative to docroot @@ -1456,11 +1456,11 @@ MESSAGE $fileUrl = Injector::inst()->get(ResourceURLGenerator::class)->urlForResource($filePath); $fileUrlDir = dirname($fileUrl); $content = preg_replace_callback('#(url\([\n\r\s\'"]*)([^\s\)\?\'"]+)#i', function ($match) use ($fileUrlDir) { - [ $_, $prefix, $relativePath ] = $match; + [ $fullMatch, $prefix, $relativePath ] = $match; if ($relativePath[0] === '/' || false !== strpos($relativePath, '://')) { return $prefix . $relativePath; } - $full = FilesystemPath::canonicalize($fileUrlDir . '/' . $relativePath); + $full = FilesystemPath::canonicalize(FilesystemPath::join($fileUrlDir, $relativePath)); return $prefix . $full; }, $content); return $content; diff --git a/tests/php/View/RequirementsTest.php b/tests/php/View/RequirementsTest.php index 727d26eb0..69144ea5b 100644 --- a/tests/php/View/RequirementsTest.php +++ b/tests/php/View/RequirementsTest.php @@ -280,7 +280,7 @@ class RequirementsTest extends SapphireTest $this->assertStringContainsString( ".p4 { background: url(/four.gif); }", $content, - 'combined css url resolver decoded 4 double-dot when only 4 levels available' + 'combined css url resolver decoded 4 double-dot when only 3 levels available' ); /* COMBINED CSS URL RESOLVER MODIFIED AN ARBITRARY VALUE */