diff --git misc/autocomplete.js misc/autocomplete.js index d66054b..5dbb58c 100644 --- misc/autocomplete.js +++ misc/autocomplete.js @@ -291,7 +291,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 modules/taxonomy/taxonomy.module modules/taxonomy/taxonomy.module index 6cacb25..a7e4f30 100644 --- modules/taxonomy/taxonomy.module +++ modules/taxonomy/taxonomy.module @@ -313,6 +313,18 @@ 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', + // Needed for menu_tail_load(). + 'load arguments' => array('%map', '%index'), + ); + // This is needed because the autocomplete system relies on this path existing. + // See: http://drupal.org/node/93854 $items['taxonomy/autocomplete'] = array( 'title' => 'Autocomplete taxonomy', 'page callback' => 'taxonomy_autocomplete', diff --git modules/taxonomy/taxonomy.test modules/taxonomy/taxonomy.test index 0664c52..8385d09 100644 --- modules/taxonomy/taxonomy.test +++ modules/taxonomy/taxonomy.test @@ -601,6 +601,27 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { } /** + * Test term autocompletion edge cases. + */ + function testTermAutocompletion() { + $base = $this->randomName(2); + // Add a term with a slash in the name. + $term = $this->createTerm($this->vocabulary); + $term->name = $base . '/' . $this->randomName(); + taxonomy_term_save($term); + // Add a term with a slash in the name. + $term = $this->createTerm($this->vocabulary); + $term->name = $base . '/' . $this->randomName(); + taxonomy_term_save($term); + + // Try to autocomplete the term name, that contains a slash. + // We should only get a single term returned. + $input = substr($term->name, 0, 5); + $this->drupalGet('taxonomy/autocomplete/taxonomy_' . $this->vocabulary->machine_name . '/' . $input); + $this->assertRaw(drupal_json_encode(array($term->name => check_plain($term->name))), t('Autocomplete returns term %term_name after typing the first 4 letters, including a slash in the name.', array('%term_name' => $term->name))); + } + + /** * Save, edit and delete a term using the user interface. */ function testTermInterface() {