Bug 1519711 - Make nsIURI::SchemeIs return false when passed null scheme r=qdot
authorValentin Gosu <valentin.gosu@gmail.com>
Sun, 13 Jan 2019 18:05:39 +0000
changeset 453702 3dc7d345da5282969b71079d483ff8c30558819d
parent 453701 c01bd7f588bd7e09b69499dbe4f9345bfbb4f9b7
child 453703 c879dc493add8fc475fc27f697460d77d213c6a8
child 453718 93c4e08b14fc730afbb76884b6e050ba6b1322ae
push id111128
push userncsoregi@mozilla.com
push dateMon, 14 Jan 2019 10:46:28 +0000
treeherdermozilla-inbound@c879dc493add [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1519711
milestone66.0a1
first release with
nightly linux32
3dc7d345da52 / 66.0a1 / 20190114104248 / files
nightly linux64
3dc7d345da52 / 66.0a1 / 20190114104248 / files
nightly mac
3dc7d345da52 / 66.0a1 / 20190114104248 / files
nightly win32
3dc7d345da52 / 66.0a1 / 20190114104248 / files
nightly win64
3dc7d345da52 / 66.0a1 / 20190114104248 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1519711 - Make nsIURI::SchemeIs return false when passed null scheme r=qdot Differential Revision: https://phabricator.services.mozilla.com/D16409
image/decoders/icon/nsIconURI.cpp
modules/libjar/nsJARURI.cpp
netwerk/base/nsSimpleURI.cpp
netwerk/base/nsStandardURL.cpp
netwerk/test/unit/test_URIs.js
--- a/image/decoders/icon/nsIconURI.cpp
+++ b/image/decoders/icon/nsIconURI.cpp
@@ -413,18 +413,21 @@ NS_IMETHODIMP
 nsMozIconURI::EqualsExceptRef(nsIURI* other, bool* result) {
   // GetRef/SetRef not supported by nsMozIconURI, so
   // EqualsExceptRef() is the same as Equals().
   return Equals(other, result);
 }
 
 NS_IMETHODIMP
 nsMozIconURI::SchemeIs(const char* aScheme, bool* aEquals) {
-  MOZ_ASSERT(aScheme);
   MOZ_ASSERT(aEquals, "null pointer");
+  if (!aScheme) {
+    *aEquals = false;
+    return NS_OK;
+  }
 
   *aEquals = PL_strcasecmp("moz-icon", aScheme) ? false : true;
   return NS_OK;
 }
 
 nsresult nsMozIconURI::Clone(nsIURI** result) {
   nsCOMPtr<nsIURL> newIconURL;
   if (mIconURL) {
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -470,18 +470,21 @@ nsJARURI::EqualsExceptRef(nsIURI *other,
 
   return refHandlingMode == eHonorRef
              ? mJAREntry->Equals(otherJAR->mJAREntry, result)
              : mJAREntry->EqualsExceptRef(otherJAR->mJAREntry, result);
 }
 
 NS_IMETHODIMP
 nsJARURI::SchemeIs(const char *i_Scheme, bool *o_Equals) {
-  MOZ_ASSERT(i_Scheme);
   MOZ_ASSERT(o_Equals);
+  if (!i_Scheme) {
+    *o_Equals = false;
+    return NS_OK;
+  }
 
   *o_Equals = PL_strcasecmp("jar", i_Scheme) ? false : true;
   return NS_OK;
 }
 
 nsresult nsJARURI::Clone(nsIURI **result) {
   nsresult rv;
 
--- a/netwerk/base/nsSimpleURI.cpp
+++ b/netwerk/base/nsSimpleURI.cpp
@@ -518,18 +518,21 @@ bool nsSimpleURI::EqualsInternal(nsSimpl
               (!mIsRefValid || mRef == otherUri->mRef));
   }
 
   return result;
 }
 
 NS_IMETHODIMP
 nsSimpleURI::SchemeIs(const char *i_Scheme, bool *o_Equals) {
-  MOZ_ASSERT(i_Scheme);
   MOZ_ASSERT(o_Equals, "null pointer");
+  if (!i_Scheme) {
+    *o_Equals = false;
+    return NS_OK;
+  }
 
   const char *this_scheme = mScheme.get();
 
   // mScheme is guaranteed to be lower case.
   if (*i_Scheme == *this_scheme || *i_Scheme == (*this_scheme - ('a' - 'A'))) {
     *o_Equals = PL_strcasecmp(this_scheme, i_Scheme) ? false : true;
   } else {
     *o_Equals = false;
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -2199,18 +2199,21 @@ nsresult nsStandardURL::EqualsInternal(
   // same file, so they are different.
   *result = false;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsStandardURL::SchemeIs(const char *scheme, bool *result) {
-  MOZ_ASSERT(scheme);
   MOZ_ASSERT(result, "null pointer");
+  if (!scheme) {
+    *result = false;
+    return NS_OK;
+  }
 
   *result = SegmentIs(mScheme, scheme);
   return NS_OK;
 }
 
 /* virtual */ nsStandardURL *nsStandardURL::StartClone() {
   nsStandardURL *clone = new nsStandardURL();
   return clone;
--- a/netwerk/test/unit/test_URIs.js
+++ b/netwerk/test/unit/test_URIs.js
@@ -605,22 +605,37 @@ function check_space_escaping()
   uri = gIoService.newURI("data:text/plain,hello world#space%20hash");
   Assert.equal(uri.spec, "data:text/plain,hello world#space%20hash");
   uri = gIoService.newURI("data:text/plain,hello world#space hash");
   Assert.equal(uri.spec, "data:text/plain,hello world#space%20hash");
   uri = gIoService.newURI("http://example.com/test path#test path");
   uri = gIoService.newURI("http://example.com/test%20path#test%20path");
 }
 
+function check_schemeIsNull()
+{
+  let uri = gIoService.newURI("data:text/plain,aaa");
+  Assert.ok(!uri.schemeIs(null));
+  uri = gIoService.newURI("http://example.com");
+  Assert.ok(!uri.schemeIs(null));
+  uri = gIoService.newURI("dummyscheme://example.com");
+  Assert.ok(!uri.schemeIs(null));
+  uri = gIoService.newURI("jar:resource://gre/chrome.toolkit.jar!/");
+  Assert.ok(!uri.schemeIs(null));
+  uri = gIoService.newURI("moz-icon://.unknown?size=32");
+  Assert.ok(!uri.schemeIs(null));
+}
+
 // TEST MAIN FUNCTION
 // ------------------
 function run_test()
 {
   check_nested_mutations();
   check_space_escaping();
+  check_schemeIsNull();
 
   // UTF-8 check - From bug 622981
   // ASCII
   let base = gIoService.newURI("http://example.org/xenia?");
   let resolved = gIoService.newURI("?x", null, base);
   let expected = gIoService.newURI("http://example.org/xenia?x");
   do_info("Bug 662981: ACSII - comparing " + resolved.spec + " and " + expected.spec);
   Assert.ok(resolved.equals(expected));