? 371235-patched-benchmarks.txt ? 371235-unpatched-benchmarks.txt ? sites/all/modules/cvs Index: includes/path.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/path.inc,v retrieving revision 1.32 diff -u -p -r1.32 path.inc --- includes/path.inc 4 Jan 2009 20:04:32 -0000 1.32 +++ includes/path.inc 26 Feb 2009 00:04:42 -0000 @@ -260,3 +260,31 @@ function drupal_match_path($path, $patte } return (bool)preg_match($regexps[$patterns], $path); } + +/* + * Extract part of the current Drupal path from a certain 'argument' onward. + * + * For example, if the path is 'http://example-drupal/blah/foo/foobar/ferzle': + * $pos = 0, returns 'blah/foo/foobar/ferzle' + * $pos = 2, returns 'foobar/ferzle' + * $pos = 4, returns '' + * + * @param $index + * The index of the component, where each component is separated by a '/' + * (forward-slash), and where the first component has an index of 0 (zero). + * @param $path + * The path to operate on, default is $_GET['q']. + * @return + * The extracted part of the path. + */ +function drupal_get_path_segment($index = 0, $path = NULL, $default = '') { + if (!isset($path)) { + $path = trim($_GET['q']); + } + + $path = explode('/', $path, $index + 1); + $path = (count($path) > $index ? end($path) : $default); + + return $path; +} + Index: modules/path/path.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.admin.inc,v retrieving revision 1.17 diff -u -p -r1.17 path.admin.inc --- modules/path/path.admin.inc 13 Jan 2009 19:27:21 -0000 1.17 +++ modules/path/path.admin.inc 26 Feb 2009 00:04:44 -0000 @@ -11,7 +11,8 @@ * When filter key passed, perform a standard search on the given key, * and return the list of matching URL aliases. */ -function path_admin_overview($keys = NULL) { +function path_admin_overview() { + $keys = drupal_get_path_segment(4); // Add the filter form above the overview table. $output = drupal_get_form('path_admin_filter_form', $keys); // Enable language column if locale is enabled or if we have any alias with language @@ -239,12 +240,3 @@ function path_admin_filter_form_submit_r $form_state['redirect'] = 'admin/build/path/list'; } - -/** - * Helper function for grabbing filter keys. - */ -function path_admin_filter_get_keys() { - // Extract keys as remainder of path - $path = explode('/', $_GET['q'], 5); - return count($path) == 5 ? $path[4] : ''; -} Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.283 diff -u -p -r1.283 search.module --- modules/search/search.module 4 Jan 2009 16:10:48 -0000 1.283 +++ modules/search/search.module 26 Feb 2009 00:04:45 -0000 @@ -997,21 +997,6 @@ function do_search($keywords, $type, $jo } /** - * Helper function for grabbing search keys. - */ -function search_get_keys() { - static $return; - if (!isset($return)) { - // Extract keys as remainder of path - // Note: support old GET format of searches for existing links. - $path = explode('/', $_GET['q'], 3); - $keys = empty($_REQUEST['keys']) ? '' : $_REQUEST['keys']; - $return = count($path) == 3 ? $path[2] : $keys; - } - return $return; -} - -/** * @defgroup search Search interface * @{ * The Drupal search interface manages a global search mechanism. Index: modules/search/search.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.pages.inc,v retrieving revision 1.5 diff -u -p -r1.5 search.pages.inc --- modules/search/search.pages.inc 14 Apr 2008 17:48:41 -0000 1.5 +++ modules/search/search.pages.inc 26 Feb 2009 00:04:45 -0000 @@ -21,7 +21,7 @@ function search_view($type = 'node') { drupal_goto('search/node'); } - $keys = search_get_keys(); + $keys = drupal_get_path_segment(2, $_GET['q'], empty($_REQUEST['keys']) ? '' : $_REQUEST['keys']); // Only perform search if there is non-whitespace search term: $results = ''; if (trim($keys)) { Index: modules/system/system.test =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.test,v retrieving revision 1.39 diff -u -p -r1.39 system.test --- modules/system/system.test 11 Feb 2009 05:33:18 -0000 1.39 +++ modules/system/system.test 26 Feb 2009 00:04:51 -0000 @@ -895,3 +895,31 @@ class SystemThemeFunctionalTest extends $this->assertRaw('themes/garland', t('Site default theme used on the add content page.')); } } + +/** + * Tests for the drupal_get_path_segment() function. + */ +class PathGetSegmentUnitTest extends DrupalWebTestCase { + function getInfo() { + return array( + 'name' => t('Tests for the drupal_get_path_segment() function'), + 'description' => t('Confirm that drupal_get_path_segment() works correctly with various input.'), + 'group' => t('Path'), + ); + } + + function testPathGetSegment() { + $segments = array( + 0 => 'test/kittens/drupal is fun?/seriously!', + 1 => 'kittens/drupal is fun?/seriously!', + 2 => 'drupal is fun?/seriously!', + 3 => 'seriously!', + 4 => '', + ); + + foreach ($segments as $pos => $segment) { + $this->assertIdentical($segments[$pos], drupal_get_path_segment($pos, $segments[0])); + } + } +} + Index: modules/taxonomy/taxonomy.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.pages.inc,v retrieving revision 1.23 diff -u -p -r1.23 taxonomy.pages.inc --- modules/taxonomy/taxonomy.pages.inc 27 Jan 2009 00:22:27 -0000 1.23 +++ modules/taxonomy/taxonomy.pages.inc 26 Feb 2009 00:04:52 -0000 @@ -116,7 +116,9 @@ function taxonomy_term_edit($term) { /** * Helper function for autocompletion */ -function taxonomy_autocomplete($vid, $string = '') { +function taxonomy_autocomplete($vid) { + $string = drupal_get_path_segment(3); + // The user enters a comma-separated list of tags. We only autocomplete the last tag. $array = drupal_explode_tags($string);