diff --git a/core/includes/path.inc b/core/includes/path.inc index 630b34c4ce087cf74a50a10e96e2bf41aa29608e..2c0568c9ffc3b1ebd7f60d3de93768f17c64bb15 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -13,12 +13,11 @@ * Initialize the $_GET['q'] variable to the proper normal path. */ function drupal_path_initialize() { - if (!empty($_GET['q'])) { - $_GET['q'] = drupal_get_normal_path($_GET['q']); - } - else { - $_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node')); + // Ensure $_GET['q'] is set before calling drupal_normal_path(). + if (empty($_GET['q'])) { + $_GET['q'] = variable_get('site_frontpage', 'node'); } + $_GET['q'] = drupal_get_normal_path($_GET['q']); } /** diff --git a/core/modules/simpletest/tests/path.test b/core/modules/simpletest/tests/path.test index 82598b5a2d3d043d80307424fe81aed944659809..9406a65ebe65b7b22e50a77ee174996ec414acd4 100644 --- a/core/modules/simpletest/tests/path.test +++ b/core/modules/simpletest/tests/path.test @@ -200,6 +200,14 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase { $this->assertRaw('current_path=url-alter-test/foo', t('current_path() returns the internal path.')); } + /** + * Tests that $_GET['q'] is initialized when the request path is empty. + */ + function testGetQInitialized() { + $this->drupalGet(''); + $this->assertText("\$_GET['q'] is non-empty with an empty request path.", "\$_GET['q'] is initialized with an empty request path."); + } + /** * Assert that an outbound path is altered to an expected value. * diff --git a/core/modules/simpletest/tests/url_alter_test.module b/core/modules/simpletest/tests/url_alter_test.module index e229ab98652739d1f64a243f6056af76ccc5a926..9287ff52307a77df07ada16cac2a1deee3d93039 100644 --- a/core/modules/simpletest/tests/url_alter_test.module +++ b/core/modules/simpletest/tests/url_alter_test.module @@ -30,6 +30,10 @@ function url_alter_test_foo() { * Implements hook_url_inbound_alter(). */ function url_alter_test_url_inbound_alter(&$path, $original_path, $path_language) { + if (!request_path() && !empty($_GET['q'])) { + drupal_set_message("\$_GET['q'] is non-empty with an empty request path."); + } + // Rewrite user/username to user/uid. if (preg_match('!^user/([^/]+)(/.*)?!', $path, $matches)) { if ($account = user_load_by_name($matches[1])) {