diff --git misc/autocomplete.js misc/autocomplete.js index 5e85be4..da3b820 100644 --- misc/autocomplete.js +++ 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 modules/taxonomy/taxonomy.module modules/taxonomy/taxonomy.module index f170430..8aa3f8b 100644 --- modules/taxonomy/taxonomy.module +++ modules/taxonomy/taxonomy.module @@ -312,6 +312,17 @@ 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 path is also required for autocomplete to work. $items['taxonomy/autocomplete'] = array( 'title' => 'Autocomplete taxonomy', 'page callback' => 'taxonomy_autocomplete', diff --git modules/taxonomy/taxonomy.test modules/taxonomy/taxonomy.test index a6ac332..307bbde 100644 --- modules/taxonomy/taxonomy.test +++ modules/taxonomy/taxonomy.test @@ -600,6 +600,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() {