diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-03-02 08:47:41 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-03-02 08:47:41 +0000 |
commit | c3760557bda91fa2ad044f289dcfd2ede999363d (patch) | |
tree | 9ed4f7b9ab0b216479565851f35f68a536541060 | |
parent | b25a1fd62f261c94a4acbece5f14c20c1b0d3315 (diff) | |
download | brdo-c3760557bda91fa2ad044f289dcfd2ede999363d.tar.gz brdo-c3760557bda91fa2ad044f289dcfd2ede999363d.tar.bz2 |
- Patch #243251 by naxoc, Signe, lilou, mcarbone: JavaScript requiring a query string cannot be loaded.
-rw-r--r-- | includes/common.inc | 13 | ||||
-rw-r--r-- | includes/locale.inc | 4 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 22 | ||||
-rw-r--r-- | modules/simpletest/tests/common_test.module | 15 |
4 files changed, 48 insertions, 6 deletions
diff --git a/includes/common.inc b/includes/common.inc index eb72bc311..7f140b815 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2982,7 +2982,7 @@ function drupal_pre_render_styles($elements) { // browser-caching. The string changes on every update or full cache // flush, forcing browsers to load a new copy of the files, as the // URL changed. - $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1); + $query_string = substr(variable_get('css_js_query_string', '0'), 0, 1); // Defaults for LINK and STYLE elements. $link_element_defaults = array( @@ -3037,7 +3037,8 @@ function drupal_pre_render_styles($elements) { // browser-caching. IE7 does not support a media type on the @import // statement, so we instead specify the media for the group on the // STYLE tag. - $import[] = '@import url("' . file_create_url($item['data']) . $query_string . '");'; + $query_string_separator = (strpos($item['data'], '?') !== FALSE) ? '&' : '?'; + $import[] = '@import url("' . check_plain(file_create_url($item['data']) . $query_string_separator . $query_string) . '");'; } // In addition to IE's limit of 31 total CSS inclusion tags, it also // has a limit of 31 @import statements per STYLE tag. @@ -3058,7 +3059,8 @@ function drupal_pre_render_styles($elements) { $element = $link_element_defaults; // The dummy query string needs to be added to the URL to control // browser-caching. - $element['#attributes']['href'] = file_create_url($item['data']) . $query_string; + $query_string_separator = (strpos($item['data'], '?') !== FALSE) ? '&' : '?'; + $element['#attributes']['href'] = file_create_url($item['data']) . $query_string_separator . $query_string; $element['#attributes']['media'] = $item['media']; $element['#browsers'] = $group['browsers']; $elements[] = $element; @@ -3628,7 +3630,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { // URL changed. Files that should not be cached (see drupal_add_js()) // get REQUEST_TIME as query-string instead, to enforce reload on every // page request. - $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1); + $query_string = substr(variable_get('css_js_query_string', '0'), 0, 1); // For inline Javascript to validate as XHTML, all Javascript containing // XHTML needs to be wrapped in CDATA. To make that backwards compatible @@ -3674,7 +3676,8 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { if ($item['defer']) { $js_element['#attributes']['defer'] = 'defer'; } - $js_element['#attributes']['src'] = file_create_url($item['data']) . ($item['cache'] ? $query_string : '?' . REQUEST_TIME); + $query_string_separator = (strpos($item['data'], '?') !== FALSE) ? '&' : '?'; + $js_element['#attributes']['src'] = file_create_url($item['data']) . $query_string_separator . ($item['cache'] ? $query_string : REQUEST_TIME); $no_preprocess .= theme('html_tag', array('element' => $js_element)); } else { diff --git a/includes/locale.inc b/includes/locale.inc index f9c1481d1..c8b451eef 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -1158,6 +1158,10 @@ function _locale_import_parse_quoted($string) { function _locale_parse_js_file($filepath) { global $language; + // The file path might contain a query string, so make sure we only use the + // actual file. + $parsed_url = drupal_parse_url($filepath); + $filepath = $parsed_url['path']; // Load the JavaScript file. $file = file_get_contents($filepath); diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 9a93d75c8..aa8f9d422 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -503,7 +503,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase { } function setUp() { - parent::setUp('php', 'locale'); + parent::setUp('php', 'locale', 'common_test'); // Reset drupal_add_css() before each test. drupal_static_reset('drupal_add_css'); } @@ -682,6 +682,16 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase { // Change the language back to left to right. $language->direction = LANGUAGE_LTR; } + + /** + * Tests that the query string remains intact when adding CSS files that have + * query string parameters. + */ + function testAddCssFileWithQueryString() { + $this->drupalGet('common-test/query-string'); + $query_string = substr(variable_get('css_js_query_string', '0'), 0, 1); + $this->assertRaw(drupal_get_path('module', 'node') . '/node.css?arg1=value1&arg2=value2&' . $query_string, t('Query string was appended correctly to css.')); + } } /** @@ -1255,6 +1265,16 @@ class JavaScriptTestCase extends DrupalWebTestCase { $scripts = drupal_get_js(); $this->assertTrue(strpos($scripts, 'misc/farbtastic/farbtastic.js'), t('The attached_library property adds the additional libraries.')); } + + /** + * Tests that the query string remains intact when adding JavaScript files + * that have query string parameters. + */ + function testAddJsFileWithQueryString() { + $this->drupalGet('common-test/query-string'); + $query_string = substr(variable_get('css_js_query_string', '0'), 0, 1); + $this->assertRaw(drupal_get_path('module', 'node') . '/node.js?arg1=value1&arg2=value2&' . $query_string, t('Query string was appended correctly to js.')); + } } /** diff --git a/modules/simpletest/tests/common_test.module b/modules/simpletest/tests/common_test.module index 36697b5af..a80f00f74 100644 --- a/modules/simpletest/tests/common_test.module +++ b/modules/simpletest/tests/common_test.module @@ -35,6 +35,12 @@ function common_test_menu() { 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); + $items['common-test/query-string'] = array( + 'title' => 'Test querystring', + 'page callback' => 'common_test_js_and_css_querystring', + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + ); return $items; } @@ -183,3 +189,12 @@ function common_test_library() { ); return $libraries; } + +/** + * Adds a JavaScript file and a CSS file with a query string appended. + */ +function common_test_js_and_css_querystring() { + drupal_add_js(drupal_get_path('module', 'node') . '/node.js?arg1=value1&arg2=value2'); + drupal_add_css(drupal_get_path('module', 'node') . '/node.css?arg1=value1&arg2=value2'); + return ''; +} |