From 16a1c032d44fadbed3b0b599c7c490bf602fca02 Mon Sep 17 00:00:00 2001
From: Steven Jones <steven.jones@computerminds.co.uk>
Date: Tue, 5 Apr 2011 07:13:30 +0100
Subject: [PATCH 1/2] Check for a full autocomplete path, not the base.

---
 includes/form.inc |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/includes/form.inc b/includes/form.inc
index c0163ca..2b7e03a 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -3636,7 +3636,7 @@ function theme_textfield($variables) {
   _form_set_class($element, array('form-text'));
 
   $extra = '';
-  if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
+  if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'] . '/dummy')) {
     drupal_add_library('system', 'drupal.autocomplete');
     $element['#attributes']['class'][] = 'form-autocomplete';
 
-- 
1.7.4.1


From 66a81b7a64d8d87b28a59453c8075d8625b2aeed Mon Sep 17 00:00:00 2001
From: Steven Jones <steven.jones@computerminds.co.uk>
Date: Tue, 5 Apr 2011 07:14:05 +0100
Subject: [PATCH 2/2] Fix autocompletion of taxonomy terms with slashes.

---
 misc/autocomplete.js             |    2 +-
 modules/taxonomy/taxonomy.module |    6 ++++--
 modules/taxonomy/taxonomy.test   |   21 +++++++++++++++++++++
 3 files changed, 26 insertions(+), 3 deletions(-)

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 f170430..1db0f4c 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -312,14 +312,16 @@ function taxonomy_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'taxonomy.pages.inc',
   );
-  $items['taxonomy/autocomplete'] = array(
+  $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'),
   );
-
   $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 a6ac332..307bbde 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/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() {
-- 
1.7.4.1

