summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2013-08-10 10:49:54 (GMT)
committerNathaniel Catchpole2013-08-10 10:49:54 (GMT)
commitccc7822c4da7823943b3f8611449d7e49f4b58da (patch)
tree3e43788dc7ecc535374d35f22c545dfd6695a838
parent6f1e25234beba1f0ceea92421f71573306861321 (diff)
Issue #1198904 by jox, das-peter: Fixed drupal_load_stylsheet() does not comply with standards when using @import.
-rw-r--r--core/lib/Drupal/Core/Asset/CssOptimizer.php10
-rw-r--r--core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php18
-rw-r--r--core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css29
-rw-r--r--core/tests/Drupal/Tests/Core/Asset/css_test_files/css_subfolder/css_input_with_import.css.optimized.css6
4 files changed, 60 insertions, 3 deletions
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 @@ class CssOptimizer implements AssetOptimizerInterface {
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..129adf5 100644
--- a/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Asset/CssOptimizerUnitTest.php
@@ -169,7 +169,23 @@ class CssOptimizerUnitTest extends UnitTestCase {
'browsers' => array('IE' => TRUE, '!IE' => TRUE),
),
'#home body { position: fixed; }',
- )
+ ),
+ // File in subfolder. Tests:
+ // - CSS import path is properly interpreted. (https://drupal.org/node/1198904)
+ 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;}