diff --git a/core/lib/Drupal/Core/Render/Element/FormElement.php b/core/lib/Drupal/Core/Render/Element/FormElement.php
index 173a55c..b2d9b90 100644
--- a/core/lib/Drupal/Core/Render/Element/FormElement.php
+++ b/core/lib/Drupal/Core/Render/Element/FormElement.php
@@ -130,7 +130,9 @@ public static function processAutocomplete(&$element, FormStateInterface $form_s
         $element['#attributes']['class'][] = 'form-autocomplete';
         $metadata->addAttachments(['library' => ['core/drupal.autocomplete']]);
         // Provide a data attribute for the JavaScript behavior to bind to.
-        $element['#attributes']['data-autocomplete-path'] = $url->getGeneratedUrl();
+        // Prefix the uri with the script name to bypass relative urls - forcing
+        // non-clean urls. e.g. index.php/some/path.
+        $element['#attributes']['data-autocomplete-path'] = \Drupal::request()->getScriptName() . '/' . $url->getGeneratedUrl();
         $metadata = $metadata->merge($url);
       }
       $metadata
diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js
index f826281..4f038a7 100644
--- a/core/misc/autocomplete.js
+++ b/core/misc/autocomplete.js
@@ -57,7 +57,10 @@
    * @return {string}
    */
   function extractLastTerm(terms) {
-    return autocomplete.splitValues(terms).pop();
+    var term = autocomplete.splitValues(terms).pop();
+    // The pattern ../ is stripped since it may be misinterpreted by the
+    // browser.
+    return term.replace(/^\s+|\.{2,}\/|\s+$/g, '');
   }
 
   /**
