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 dc2847d..6d2dddd 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -312,6 +312,7 @@ function taxonomy_menu() { 'type' => MENU_CALLBACK, 'file' => 'taxonomy.pages.inc', ); + $items['taxonomy/autocomplete'] = array( 'title' => 'Autocomplete taxonomy', 'page callback' => 'taxonomy_autocomplete', @@ -320,6 +321,16 @@ function taxonomy_menu() { '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', 'title arguments' => array(3), diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index aa7cc2e..d52664d 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -641,6 +641,31 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase { } /** + * Test term autocompletion edge cases. + */ + function testTermAutocompletion() { + $base_len = 5; + $base = $this->randomName($base_len); + // Add a term with a slash in the name. + $first_term = $this->createTerm($this->vocabulary); + $first_term->name = $base . '/' . $this->randomName(); + taxonomy_term_save($first_term); + // Add another term that differs after the slash character. + $search_term = $this->createTerm($this->vocabulary); + $search_term->name = $base . '/' . $this->randomName(); + taxonomy_term_save($search_term); + + // Try to autocomplete a term name that contains a slash. + // We should only get a single term returned. + $input = substr($search_term->name, 0, $base_len + 3); + $url = 'taxonomy/autocomplete/taxonomy_'; + $url .= $this->vocabulary->machine_name . '/' . $input; + $this->drupalGet($url); + $target = array($search_term->name => check_plain($search_term->name)); + $this->assertRaw(drupal_json_encode($target), t('Autocomplete returns term %term_name after typing the first %num letters, including a slash in the name.', array('%term_name' => $search_term->name, '%num' => $base_len + 3))); + } + + /** * Save, edit and delete a term using the user interface. */ function testTermInterface() {