diff --git a/core/lib/Drupal/Core/Asset/CssOptimizer.php b/core/lib/Drupal/Core/Asset/CssOptimizer.php index 2cf07e7..2165b49 100644 --- a/core/lib/Drupal/Core/Asset/CssOptimizer.php +++ b/core/lib/Drupal/Core/Asset/CssOptimizer.php @@ -96,17 +96,23 @@ public function loadFile($file, $optimize = NULL, $reset_basepath = TRUE) { if ($basepath && !file_uri_scheme($file)) { $file = $basepath . '/' . $file; } + // Store the parent base path to restore it later. + $parent_base_path = $basepath; + // Set the current base path to process possible child imports. $basepath = dirname($file); // Load the CSS stylesheet. We suppress errors because themes may specify // stylesheets in their .info.yml file that don't exist in the theme's path, // but are merely there to disable certain module CSS files. + $content = ''; if ($contents = @file_get_contents($file)) { // Return the processed stylesheet. - return $this->processCss($contents, $_optimize); + $content = $this->processCss($contents, $_optimize); } - return ''; + // Restore the parent base path as the file and its childen are processed. + $basepath = $parent_base_path; + return $content; } /** diff --git a/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php b/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php index 41eb529..f37d716 100644 --- a/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php @@ -169,7 +169,23 @@ function testOptimizeProvider() { 'browsers' => array('IE' => TRUE, '!IE' => TRUE), ), '#home body { position: fixed; }', - ) + ), + // Subfolder file. Tests: + // - CSS import path is properly interpreted. + 5 => array( + array( + 'group' => -100, + 'every_page' => TRUE, + 'type' => 'file', + 'weight' => 0.013, + 'media' => 'all', + 'preprocess' => TRUE, + 'data' => $path . 'css_subfolder/css_input_with_import.css', + 'browsers' => array('IE' => TRUE, '!IE' => TRUE), + 'basename' => 'css_input_with_import.css', + ), + str_replace('url(../images/icon.png)', 'url(' . file_create_url($path . 'images/icon.png') . ')', file_get_contents($path . 'css_subfolder/css_input_with_import.css.optimized.css')), + ), ); } diff --git a/core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css b/core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css new file mode 100644 index 0000000..d90ecbc --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css @@ -0,0 +1,29 @@ + + +@import "../import1.css"; +@import "../import2.css"; + +body { + margin: 0; + padding: 0; + background: #edf5fa; + font: 76%/170% Verdana, sans-serif; + color: #494949; +} + +.this .is .a .test { + font: 1em/100% Verdana, sans-serif; + color: #494949; +} +.this +.is +.a +.test { +font: 1em/100% Verdana, sans-serif; +color: #494949; +} + +textarea, select { + font: 1em/160% Verdana, sans-serif; + color: #494949; +} diff --git a/core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css.optimized.css b/core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css.optimized.css new file mode 100644 index 0000000..aba3b21 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css.optimized.css @@ -0,0 +1,6 @@ +ul,select{font:1em/160% Verdana,sans-serif;color:#494949;}.ui-icon{background-image:url(../images/icon.png);} +p,select{font:1em/160% Verdana,sans-serif;color:#494949;} +body{margin:0;padding:0;background:#edf5fa;font:76%/170% Verdana,sans-serif;color:#494949;}.this .is .a .test{font:1em/100% Verdana,sans-serif;color:#494949;}.this +.is +.a +.test{font:1em/100% Verdana,sans-serif;color:#494949;}textarea,select{font:1em/160% Verdana,sans-serif;color:#494949;}