summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/common.inc13
-rw-r--r--modules/simpletest/tests/common.test18
2 files changed, 30 insertions, 1 deletions
diff --git a/includes/common.inc b/includes/common.inc
index d8661100c..c264147e9 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -486,7 +486,11 @@ function drupal_get_destination() {
}
/**
- * Wrapper around parse_url() to parse a given URL into an associative array, suitable for url().
+ * Wrapper around parse_url() to parse a system URL string into an associative array, suitable for url().
+ *
+ * This function should only be used for URLs that have been generated by the
+ * system, resp. url(). It should not be used for URLs that come from external
+ * sources, or URLs that link to external resources.
*
* The returned array contains a 'path' that may be passed separately to url().
* For example:
@@ -552,6 +556,13 @@ function drupal_parse_url($url) {
$options['fragment'] = $parts['fragment'];
}
}
+ // The 'q' parameter contains the path of the current page if clean URLs are
+ // disabled. It overrides the 'path' of the URL when present, even if clean
+ // URLs are enabled, due to how Apache rewriting rules work.
+ if (isset($options['query']['q'])) {
+ $options['path'] = $options['query']['q'];
+ unset($options['query']['q']);
+ }
return $options;
}
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index fe37b416a..53d493210 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -120,6 +120,24 @@ class CommonURLUnitTest extends DrupalUnitTestCase {
'fragment' => 'foo',
);
$this->assertEqual(drupal_parse_url($url), $result, t('External URL parsed correctly.'));
+
+ // Verify proper parsing of URLs when clean URLs are disabled.
+ $result = array(
+ 'path' => 'foo/bar',
+ 'query' => array('bar' => 'baz'),
+ 'fragment' => 'foo',
+ );
+ // Non-clean URLs #1: Absolute URL generated by url().
+ $url = $GLOBALS['base_url'] . '/?q=foo/bar&bar=baz#foo';
+ $this->assertEqual(drupal_parse_url($url), $result, t('Absolute URL with clean URLs disabled parsed correctly.'));
+
+ // Non-clean URLs #2: Relative URL generated by url().
+ $url = '?q=foo/bar&bar=baz#foo';
+ $this->assertEqual(drupal_parse_url($url), $result, t('Relative URL with clean URLs disabled parsed correctly.'));
+
+ // Non-clean URLs #3: URL generated by url() on non-Apache webserver.
+ $url = 'index.php?q=foo/bar&bar=baz#foo';
+ $this->assertEqual(drupal_parse_url($url), $result, t('Relative URL on non-Apache webserver with clean URLs disabled parsed correctly.'));
}
/**