diff --git a/misc/autocomplete.js b/misc/autocomplete.js
index 489e2fb1b5618a46181b73adcb5165c78366fbb1..8c839c7c31f14d49f0ed836071ade7ef7dacd7bc 100644
--- a/misc/autocomplete.js
+++ b/misc/autocomplete.js
@@ -256,7 +256,8 @@ Drupal.ACDB.prototype.search = function (searchString) {
 
   // See if this string needs to be searched for anyway.
   searchString = searchString.replace(/^\s+|\s+$/, '');
-  if (searchString.charAt(searchString.length - 1) == ',') {
+  if (searchString.length <= 0 ||
+    searchString.charAt(searchString.length - 1) == ',') {
     return;
   }