Bug 775072 - Inline autocomplete munges URLs that contain characters that would normally be escaped. r=mak
authorBlair McBride <bmcbride@mozilla.com>
Thu, 23 Aug 2012 00:44:19 +1200
changeset 105044 e1cdfebb423df4287eac249fc9b36d355505cb56
parent 105043 df17d6a5a330a812091bfb6754cacdceebaf90a8
child 105045 5fb14f57f34ac0ded126cb7e53454cf4c01654d3
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersmak
bugs775072
milestone17.0a1
Bug 775072 - Inline autocomplete munges URLs that contain characters that would normally be escaped. r=mak
toolkit/components/places/nsPlacesAutoComplete.js
toolkit/components/places/tests/inline/test_trimming.js
--- a/toolkit/components/places/nsPlacesAutoComplete.js
+++ b/toolkit/components/places/nsPlacesAutoComplete.js
@@ -126,33 +126,45 @@ function initTempTable(aDatabase)
  * care about for searching.
  *
  * @param aURIString
  *        The text to unescape and modify.
  * @return the modified uri.
  */
 function fixupSearchText(aURIString)
 {
+  let uri = stripPrefix(aURIString);
+  return gTextURIService.unEscapeURIForUI("UTF-8", uri);
+}
+
+/**
+ * Strip prefixes from the URI that we don't care about for searching.
+ *
+ * @param aURIString
+ *        The text to modify.
+ * @return the modified uri.
+ */
+function stripPrefix(aURIString)
+{
   let uri = aURIString;
 
   if (uri.indexOf("http://") == 0) {
     uri = uri.slice(7);
   }
   else if (uri.indexOf("https://") == 0) {
     uri = uri.slice(8);
   }
   else if (uri.indexOf("ftp://") == 0) {
     uri = uri.slice(6);
   }
 
   if (uri.indexOf("www.") == 0) {
     uri = uri.slice(4);
   }
-
-  return gTextURIService.unEscapeURIForUI("UTF-8", uri);
+  return uri;
 }
 
 /**
  * safePrefGetter get the pref with typo safety.
  * This will return the default value provided if no pref is set.
  *
  * @param aPrefBranch
  *        The nsIPrefBranch containing the required preference
@@ -1482,17 +1494,17 @@ urlInlineComplete.prototype = {
   //// mozIStorageStatementCallback
 
   handleResult: function UIC_handleResult(aResultSet)
   {
     let row = aResultSet.getNextRow();
     let value = row.getResultByIndex(0);
     let url = fixupSearchText(value);
 
-    let prefix = value.slice(0, value.length - url.length);
+    let prefix = value.slice(0, value.length - stripPrefix(value).length);
 
     // We must complete the URL up to the next separator (which is /, ? or #).
     let separatorIndex = url.slice(this._currentSearchString.length)
                             .search(/[\/\?\#]/);
     if (separatorIndex != -1) {
       separatorIndex += this._currentSearchString.length;
       if (url[separatorIndex] == "/") {
         separatorIndex++; // Include the "/" separator
--- a/toolkit/components/places/tests/inline/test_trimming.js
+++ b/toolkit/components/places/tests/inline/test_trimming.js
@@ -127,8 +127,18 @@ add_autocomplete_test([
   function () {
     // The .co should be preferred, but should not get the https from the .com.
     // The .co domain must be added later to activate the trigger bug.
     addBookmark({ url: "https://mozilla.com/" });
     addBookmark({ url: "http://mozilla.co/" });
     addBookmark({ url: "http://mozilla.co/" });
   },
 ]);
+
+add_autocomplete_test([
+  "Searching for URL with characters that are normally escaped",
+  "https://www.mozilla.org/啊-test",
+  { autoFilled: "https://www.mozilla.org/啊-test", completed: "https://www.mozilla.org/啊-test" },
+  function () {
+    addVisits({ uri: NetUtil.newURI("https://www.mozilla.org/啊-test"),
+                transition: TRANSITION_TYPED });
+  },
+]);