diff --git a/core/includes/common.inc b/core/includes/common.inc index 9da67ac..4aa4e19 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3509,10 +3509,17 @@ function _drupal_build_css_path($matches, $base = NULL) { * Contents of the stylesheet, including any resolved @import commands. */ function drupal_load_stylesheet($file, $optimize = NULL, $reset_basepath = TRUE) { + // $basepath_stack is used to ensure that @import statements will be resolved + // correctly and thus the following requirements will be satisfied: + // For any (also nested) @import statement, the path that is used as base path + // (or current directory) to resolve a relative url, must be the path (directory) + // of the file containing the @import statement. + // These statics are not cache variables, so we don't use drupal_static(). - static $_optimize, $basepath; + static $_optimize, $basepath, $basepath_stack; if ($reset_basepath) { $basepath = ''; + $basepath_stack = array(); } // Store the value of $optimize for preg_replace_callback with nested // @import loops. @@ -3525,17 +3532,19 @@ function drupal_load_stylesheet($file, $optimize = NULL, $reset_basepath = TRUE) if ($basepath && !file_uri_scheme($file)) { $file = $basepath . '/' . $file; } + array_push($basepath_stack, $basepath); $basepath = dirname($file); // Load the CSS stylesheet. We suppress errors because themes may specify // stylesheets in their .info file that don't exist in the theme's path, // but are merely there to disable certain module CSS files. + $result = ''; if ($contents = @file_get_contents($file)) { // Return the processed stylesheet. - return drupal_load_stylesheet_content($contents, $_optimize); + $result = drupal_load_stylesheet_content($contents, $_optimize); } - - return ''; + $basepath = array_pop($basepath_stack); + return $result; } /** diff --git a/core/modules/simpletest/files/css_test_files/css_input_with_import.css.unoptimized.css b/core/modules/simpletest/files/css_test_files/css_input_with_import.css.unoptimized.css index 4c905f5..19323c1 100644 --- a/core/modules/simpletest/files/css_test_files/css_input_with_import.css.unoptimized.css +++ b/core/modules/simpletest/files/css_test_files/css_input_with_import.css.unoptimized.css @@ -1,6 +1,16 @@ +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 { diff --git a/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css new file mode 100644 index 0000000..5ed72ee --- /dev/null +++ b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css @@ -0,0 +1,30 @@ + + +@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/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.optimized.css b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.optimized.css new file mode 100644 index 0000000..aba3b21 --- /dev/null +++ b/core/modules/simpletest/files/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;} diff --git a/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.unoptimized.css b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.unoptimized.css new file mode 100644 index 0000000..50fb4a8 --- /dev/null +++ b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.unoptimized.css @@ -0,0 +1,40 @@ + + + +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; +} + diff --git a/core/modules/simpletest/tests/common.test b/core/modules/simpletest/tests/common.test index 8936808..7ba2670 100644 --- a/core/modules/simpletest/tests/common.test +++ b/core/modules/simpletest/tests/common.test @@ -896,12 +896,13 @@ class CascadingStylesheetsUnitTest extends DrupalUnitTestCase { $testfiles = array( 'css_input_without_import.css', 'css_input_with_import.css', + 'css_subfolder/css_input_with_import.css', 'comment_hacks.css' ); $path = drupal_get_path('module', 'simpletest') . '/files/css_test_files'; foreach ($testfiles as $file) { $expected = file_get_contents("$path/$file.unoptimized.css"); - $unoptimized_output = drupal_load_stylesheet("$path/$file.unoptimized.css", FALSE); + $unoptimized_output = drupal_load_stylesheet("$path/$file", FALSE); $this->assertEqual($unoptimized_output, $expected, t('Unoptimized CSS file has expected contents (@file)', array('@file' => $file))); $expected = file_get_contents("$path/$file.optimized.css"); @@ -910,7 +911,7 @@ class CascadingStylesheetsUnitTest extends DrupalUnitTestCase { // Repeat the tests by accessing the stylesheets by URL. $expected = file_get_contents("$path/$file.unoptimized.css"); - $unoptimized_output_url = drupal_load_stylesheet($GLOBALS['base_url'] . "/$path/$file.unoptimized.css", FALSE); + $unoptimized_output = drupal_load_stylesheet($GLOBALS['base_url'] . "/$path/$file", FALSE); $this->assertEqual($unoptimized_output, $expected, t('Unoptimized CSS file (loaded from an URL) has expected contents (@file)', array('@file' => $file))); $expected = file_get_contents("$path/$file.optimized.css");