Bug 1550945 - Part 9: Handle scheme extraction failure, hint by :emk. Return error on unknown scheme. f=valentin, r=me
authorJorg K <jorgk@jorgk.com>
Fri, 31 May 2019 12:04:34 +0200
changeset 35730 538ca411c73d9cbcb93216d3e6f90925217e3428
parent 35729 0cc63242c9a4f3441112010907fb65c4a49d4f24
child 35731 f70bf49b71f21a81cc2533b11f4d4f4717eeb422
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersme
bugs1550945
Bug 1550945 - Part 9: Handle scheme extraction failure, hint by :emk. Return error on unknown scheme. f=valentin, r=me
mailnews/base/util/nsNewMailnewsURI.cpp
--- a/mailnews/base/util/nsNewMailnewsURI.cpp
+++ b/mailnews/base/util/nsNewMailnewsURI.cpp
@@ -18,17 +18,25 @@
 #include "../src/nsCidProtocolHandler.h"
 
 nsresult NS_NewMailnewsURI(nsIURI** aURI, const nsACString& aSpec,
                            const char* aCharset /* = nullptr */,
                            nsIURI* aBaseURI /* = nullptr */,
                            nsIIOService* aIOService /* = nullptr */) {
   nsAutoCString scheme;
   nsresult rv = net_ExtractURLScheme(aSpec, scheme);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_FAILED(rv)) {
+    // then aSpec is relative
+    if (!aBaseURI) {
+      return NS_ERROR_MALFORMED_URI;
+    }
+
+    rv = aBaseURI->GetScheme(scheme);
+    if (NS_FAILED(rv)) return rv;
+  }
 
   if (scheme.EqualsLiteral("mailbox") ||
       scheme.EqualsLiteral("mailbox-message")) {
     return nsMailboxService::NewURI(aSpec, aCharset, aBaseURI, aURI);
   }
   if (scheme.EqualsLiteral("imap") || scheme.EqualsLiteral("imap-message")) {
     return nsImapService::NewURI(aSpec, aCharset, aBaseURI, aURI);
   }
@@ -57,28 +65,28 @@ nsresult NS_NewMailnewsURI(nsIURI** aURI
     rv = url->Init(nsIStandardURL::URLTYPE_STANDARD,
                    scheme.EqualsLiteral("ldap") ? 389 : 636, aSpec, aCharset,
                    aBaseURI);
     NS_ENSURE_SUCCESS(rv, rv);
     url.forget(aURI);
     return NS_OK;
   }
   if (scheme.EqualsLiteral("smile")) {
-    ;  // Fall through.
+    return NS_MutateURI(new mozilla::net::nsSimpleURI::Mutator())
+        .SetSpec(aSpec)
+        .Finalize(aURI);
   }
   if (scheme.EqualsLiteral("moz-cal-handle-itip")) {
     return NS_MutateURI(new mozilla::net::nsStandardURL::Mutator())
         .SetSpec(aSpec)
         .Finalize(aURI);
   }
   if (scheme.EqualsLiteral("webcal") || scheme.EqualsLiteral("webcals")) {
     return NS_MutateURI(new mozilla::net::nsStandardURL::Mutator())
         .SetSpec(aSpec)
         .Finalize(aURI);
   }
 
   // XXX TODO: What about JS Account?
 
-  // None of the above, let's fallback to the M-C fallback.
-  return NS_MutateURI(new mozilla::net::nsSimpleURI::Mutator())
-      .SetSpec(aSpec)
-      .Finalize(aURI);
+  // None of the above, return an error and let M-C handle it.
+  return NS_ERROR_UNKNOWN_PROTOCOL;
 }