Bug 1435319, r=valentin
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 13 Jun 2018 08:15:40 -0700
changeset 423132 b58c103b639f29520c952137cd607148e2b01675
parent 423131 1d069afa41fa40ba8c5835dbd83f1218c46b83e7
child 423133 34fc2ff698c3796600e79073daa6011f24aecc06
push id34164
push usercsabou@mozilla.com
push dateThu, 21 Jun 2018 01:17:13 +0000
treeherdermozilla-central@d231a3231680 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1435319
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1435319, r=valentin
docshell/base/nsDefaultURIFixup.cpp
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -128,32 +128,41 @@ HasUserPassword(const nsACString& aStrin
         return true;
       }
     }
   }
 
   return false;
 }
 
+// Assume that 1 tab is accidental, but more than 1 implies this is
+// supposed to be tab-separated content.
+static bool
+MaybeTabSeparatedContent(const nsCString& aStringURI)
+{
+  auto firstTab = aStringURI.FindChar('\t');
+  return firstTab != kNotFound && aStringURI.RFindChar('\t') != firstTab;
+}
+
 NS_IMETHODIMP
 nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI,
                                    uint32_t aFixupFlags,
                                    nsIInputStream** aPostData,
                                    nsIURIFixupInfo** aInfo)
 {
   NS_ENSURE_ARG(!aStringURI.IsEmpty());
 
   nsresult rv;
 
   nsAutoCString uriString(aStringURI);
 
   // Eliminate embedded newlines, which single-line text fields now allow:
   uriString.StripCRLF();
-  // Cleanup the empty spaces that might be on each end:
-  uriString.Trim(" ");
+  // Cleanup the empty spaces and tabs that might be on each end:
+  uriString.Trim(" \t");
 
   NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
 
   RefPtr<nsDefaultURIFixupInfo> info = new nsDefaultURIFixupInfo(uriString);
   NS_ADDREF(*aInfo = info);
 
   nsCOMPtr<nsIIOService> ioService =
     do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
@@ -355,22 +364,26 @@ nsDefaultURIFixup::GetFixupURIInfo(const
   if (StringBeginsWith(uriString, NS_LITERAL_CSTRING("://"))) {
     uriString = StringTail(uriString, uriString.Length() - 3);
     inputHadDuffProtocol = true;
   } else if (StringBeginsWith(uriString, NS_LITERAL_CSTRING("//"))) {
     uriString = StringTail(uriString, uriString.Length() - 2);
     inputHadDuffProtocol = true;
   }
 
-  // NB: this rv gets returned at the end of this method if we never
-  // do a keyword fixup after this (because the pref or the flags passed
-  // might not let us).
-  rv = FixupURIProtocol(uriString, info, getter_AddRefs(uriWithProtocol));
-  if (uriWithProtocol) {
-    info->mFixedURI = uriWithProtocol;
+  // Note: this rv gets returned at the end of this method if we don't fix up
+  // the protocol and don't do a keyword fixup after this (because the pref
+  // or the flags passed might not let us).
+  rv = NS_OK;
+  // Avoid fixing up content that looks like tab-separated values
+  if (!MaybeTabSeparatedContent(uriString)) {
+    rv = FixupURIProtocol(uriString, info, getter_AddRefs(uriWithProtocol));
+    if (uriWithProtocol) {
+      info->mFixedURI = uriWithProtocol;
+    }
   }
 
   // See if it is a keyword
   // Test whether keywords need to be fixed up
   if (sFixupKeywords && (aFixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP) &&
       !inputHadDuffProtocol) {
     if (NS_SUCCEEDED(KeywordURIFixup(uriString, info, aPostData)) &&
         info->mPreferredURI) {