diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 412cc85..50ac754 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -272,10 +272,10 @@ gedit_utils_set_atk_relation (GtkWidget       *obj1,
 }
 
 gchar *
-gedit_utils_escape_search_text (const gchar* text)
+gedit_utils_escape_search_text (const gchar* text,
+				gint         length)
 {
 	GString *str;
-	gint length;
 	const gchar *p;
  	const gchar *end;
 
@@ -284,7 +284,8 @@ gedit_utils_escape_search_text (const gchar* text)
 
 	gedit_debug_message (DEBUG_SEARCH, "Text: %s", text);
 
-    	length = strlen (text);
+	if (length < 0)
+		length = strlen (text);
 
 	/* no escape when typing.
 	 * The short circuit works only for ascii, but we only
diff --git a/gedit/gedit-utils.h b/gedit/gedit-utils.h
index 0f54fb0..afc305a 100644
--- a/gedit/gedit-utils.h
+++ b/gedit/gedit-utils.h
@@ -90,7 +90,8 @@ void		 gedit_utils_set_atk_relation		(GtkWidget        *obj1,
 							 GtkWidget        *obj2,
 							 AtkRelationType   rel_type);
 
-gchar		*gedit_utils_escape_search_text		(const gchar      *text);
+gchar		*gedit_utils_escape_search_text		(const gchar      *text,
+							 gint              length);
 
 gchar		*gedit_utils_unescape_search_text	(const gchar      *text);
 
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index a69bb98..43cb165 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -809,7 +809,7 @@ search_entry_insert_text (GtkEditable    *editable,
 		if (insert_text)
 			return;
 
-		escaped_text = gedit_utils_escape_search_text (text);
+		escaped_text = gedit_utils_escape_search_text (text, length);
 
 		gedit_debug_message (DEBUG_SEARCH, "Escaped Text: %s", escaped_text);
 
