Bug 1047393 - Fix crash in nsIURIFixup. r=gavin, a=sledru
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 04 Aug 2014 16:44:33 +0100
changeset 217406 05c1785ef9592ceb1e8f8f51da158667c3ab6983
parent 217405 c111b7cf29ff24c2ef39d0482cc685c2c5425af2
child 217407 c5f014796d364a7fbaa5f1faf5be6d3e5ad49060
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin, sledru
bugs1047393
milestone33.0a2
Bug 1047393 - Fix crash in nsIURIFixup. r=gavin, a=sledru
docshell/base/nsDefaultURIFixup.cpp
docshell/test/unit/test_nsDefaultURIFixup_info.js
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -955,17 +955,18 @@ void nsDefaultURIFixup::KeywordURIFixup(
     }
     // ... or if there is no question mark or colon, and there is either no
     // dot, or exactly 1 and it is the first or last character of the input:
     else if ((dotLoc == uint32_t(kNotFound) ||
               (dotLoc == lastDotLoc && (dotLoc == 0 || dotLoc == aURIString.Length() - 1))) &&
              colonLoc == uint32_t(kNotFound) && qMarkLoc == uint32_t(kNotFound))
     {
         nsAutoCString asciiHost;
-        if (NS_SUCCEEDED(aFixupInfo->mFixedURI->GetAsciiHost(asciiHost)) &&
+        if (aFixupInfo->mFixedURI &&
+            NS_SUCCEEDED(aFixupInfo->mFixedURI->GetAsciiHost(asciiHost)) &&
             !asciiHost.IsEmpty())
         {
             // Check if this domain is whitelisted as an actual
             // domain (which will prevent a keyword query)
             // NB: any processing of the host here should stay in sync with
             // code in the front-end(s) that set the pref.
             nsAutoCString pref("browser.fixup.domainwhitelist.");
             if (dotLoc == aURIString.Length() - 1) {
--- a/docshell/test/unit/test_nsDefaultURIFixup_info.js
+++ b/docshell/test/unit/test_nsDefaultURIFixup_info.js
@@ -54,17 +54,18 @@ let testcases = [
   ["http://test./", "http://test./", "http://www.test./", false, false],
   ["127.0.0.1", "http://127.0.0.1/", null, false, true],
   ["1234", "http://1234/", "http://www.1234.com/", true, true],
   ["host/foo.txt", "http://host/foo.txt", "http://www.host.com/foo.txt", false, true],
   ["mozilla", "http://mozilla/", "http://www.mozilla.com/", true, true],
   ["test.", "http://test./", "http://www.test./", true, true],
   [".test", "http://.test/", "http://www..test/", true, true],
   ["mozilla is amazing", null, null, true, true],
-  ["", null, null, true, true]
+  ["", null, null, true, true],
+  ["[]", null, null, true, true]
 ];
 
 if (Services.appinfo.OS.toLowerCase().startsWith("win")) {
   testcases.push(["C:\\some\\file.txt", "file:///C:/some/file.txt", null, false, true]);
 } else {
   testcases.push(["/some/file.txt", "file:///some/file.txt", null, false, true]);
 }
 
@@ -109,17 +110,17 @@ function run_test() {
       // Check booleans on input:
       let couldDoKeywordLookup = flags & urifixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
       do_check_eq(info.fixupUsedKeyword, couldDoKeywordLookup && expectKeywordLookup);
       do_check_eq(info.fixupChangedProtocol, expectProtocolChange);
       do_check_eq(info.fixupCreatedAlternateURI, makeAlternativeURI && alternativeURI != null);
 
       // Check the preferred URI
       if (couldDoKeywordLookup && expectKeywordLookup) {
-        let urlparamInput = testInput.replace(/ /g, '+');
+        let urlparamInput = encodeURIComponent(testInput).replace("%20", "+", "g");
         let searchURL = kSearchEngineURL.replace("{searchTerms}", urlparamInput);
         do_check_eq(info.preferredURI.spec, searchURL);
       } else {
         // In these cases, we should never be doing a keyword lookup and
         // the fixed URI should be preferred:
         do_check_eq(info.preferredURI.spec, info.fixedURI.spec);
       }
       do_check_eq(testInput, info.originalInput);