Issue #3317745 by heykarthikwithu, mkalkbrenner, catch, smustgrave, Schoenef: CSS Aggregation should not rewrite # url

merge-requests/4522/head
catch 2023-08-01 10:13:20 +01:00
parent 9d3c52dd80
commit 5f07e3ce56
4 changed files with 21 additions and 2 deletions

View File

@ -90,8 +90,8 @@ class CssOptimizer implements AssetOptimizerInterface {
// Store base path.
$this->rewriteFileURIBasePath = $css_base_path . '/';
// Anchor all paths in the CSS with its base URL, ignoring external and absolute paths.
return preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\s*\)/i', [$this, 'rewriteFileURI'], $contents);
// Anchor all paths in the CSS with its base URL, ignoring external and absolute paths and paths starting with '#'.
return preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+|#|%23)([^\'")]+)[\'"]?\s*\)/i', [$this, 'rewriteFileURI'], $contents);
}
/**

View File

@ -222,6 +222,18 @@ class CssOptimizerUnitTest extends UnitTestCase {
],
file_get_contents($absolute_path . 'quotes.css.optimized.css'),
],
[
[
'group' => -100,
'type' => 'file',
'weight' => 0.013,
'media' => 'all',
'preprocess' => TRUE,
'data' => $path . 'import3.css',
'basename' => 'import3.css',
],
file_get_contents($absolute_path . 'import3.css.optimized.css'),
],
];
}

View File

@ -0,0 +1,6 @@
div {
clip-path: url('#clip-cloud');
}
div {
clip-path: url('/abc/#clip-cloud');
}

View File

@ -0,0 +1 @@
div{clip-path:url('#clip-cloud');}div{clip-path:url('/abc/#clip-cloud');}