diff --git a/misc/autocomplete.js b/misc/autocomplete.js index 5e85be4..da3b820 100644 --- a/misc/autocomplete.js +++ b/misc/autocomplete.js @@ -290,7 +290,7 @@ Drupal.ACDB.prototype.search = function (searchString) { // Ajax GET request for autocompletion. $.ajax({ type: 'GET', - url: db.uri + '/' + encodeURIComponent(searchString), + url: db.uri + '/' + Drupal.encodePath(searchString), dataType: 'json', success: function (matches) { if (typeof matches.status == 'undefined' || matches.status != 0) { diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 7921b79..e49748c 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -319,6 +319,15 @@ function taxonomy_menu() { 'type' => MENU_CALLBACK, 'file' => 'taxonomy.pages.inc', ); + $items['taxonomy/autocomplete/%/%menu_tail'] = array( + 'title' => 'Autocomplete taxonomy', + 'page callback' => 'taxonomy_autocomplete', + 'page arguments' => array(2, 3), + 'access arguments' => array('access content'), + 'type' => MENU_CALLBACK, + 'file' => 'taxonomy.pages.inc', + 'load arguments' => array('%map', '%index'), + ); $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name'] = array( 'title callback' => 'taxonomy_admin_vocabulary_title_callback', diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 9a89b9c..2963474 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -641,6 +641,38 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { } /** + * Test term autocompletion edge cases with slashes in the names. + */ + function testTermAutocompletion() { + // Add a term with a slash in the name. + $first_term = $this->createTerm($this->vocabulary); + $first_term->name = '10/16/2011'; + taxonomy_term_save($first_term); + // Add another term that differs after the slash character. + $second_term = $this->createTerm($this->vocabulary); + $second_term->name = '10/17/2011'; + taxonomy_term_save($second_term); + + // Try to autocomplete a term name that matches both terms. + // We should get both term in a json encoded string. + $input = '10/'; + $url = 'taxonomy/autocomplete/taxonomy_'; + $url .= $this->vocabulary->machine_name . '/' . $input; + $this->drupalGet($url); + $target = array($first_term->name => check_plain($first_term->name), $second_term->name => check_plain($second_term->name)); + $this->assertRaw(drupal_json_encode($target), t('Autocomplete returns all expected matching terms.')); + + // Try to autocomplete a term name that matches 1st term. + // We should only get the first term in a json encoded string. + $input = '10/16'; + $url = 'taxonomy/autocomplete/taxonomy_'; + $url .= $this->vocabulary->machine_name . '/' . $input; + $this->drupalGet($url); + $target = array($first_term->name => check_plain($first_term->name)); + $this->assertRaw(drupal_json_encode($target), t('Autocomplete returns all expected matching terms.')); + } + + /** * Save, edit and delete a term using the user interface. */ function testTermInterface() {