Skip to content

Commit

Permalink
fix: misc suggested changes
Browse files Browse the repository at this point in the history
* disable resolve_relative_css_refs by default
* variable naming
* using proper path joiner
* test comment typo
  • Loading branch information
gurucomkz committed Aug 5, 2022
1 parent bc9a323 commit ebb1601
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/View/Requirements_Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1456,11 +1456,11 @@ protected function resolveCSSReferences($content, $filePath)
$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;
Expand Down
2 changes: 1 addition & 1 deletion tests/php/View/RequirementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function testResolveCSSReferences()
$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 */
Expand Down

0 comments on commit ebb1601

Please sign in to comment.