Bug 1274044: Relax assertion in nsStandardURL for case when mDefaultPort is -1. r?valentin
The assertion is trying to require that the caller should never pass in mDefaultPort; instead, the caller should pass -1. BUT, if mDefaultPort is itself -1 (i.e. there's no default port), then we need to allow the caller to pass in -1 without spamming an assertion.
MozReview-Commit-ID: GKxndkJoXcv
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1852,17 +1852,17 @@ nsStandardURL::SetPort(int32_t port)
* - Calling InvalidateCache (since our mSpec is changing).
* - Checking whether aNewPort is mDefaultPort (in which case the
* caller should pass aNewPort=-1).
*/
void
nsStandardURL::ReplacePortInSpec(int32_t aNewPort)
{
MOZ_ASSERT(mMutable, "Caller should ensure we're mutable");
- NS_ASSERTION(aNewPort != mDefaultPort,
+ NS_ASSERTION(aNewPort != mDefaultPort || mDefaultPort == -1,
"Caller should check its passed-in value and pass -1 instead of "
"mDefaultPort, to avoid encoding default port into mSpec");
// Create the (possibly empty) string that we're planning to replace:
nsAutoCString buf;
if (mPort != -1) {
buf.Assign(':');
buf.AppendInt(mPort);
new file mode 100644
--- /dev/null
+++ b/netwerk/test/crashtests/1274044-1.html
@@ -0,0 +1,7 @@
+<script>
+
+var u = new URL("http://127.0.0.1:9607/");
+u.protocol = "resource:";
+u.port = "";
+
+</script>
--- a/netwerk/test/crashtests/crashtests.list
+++ b/netwerk/test/crashtests/crashtests.list
@@ -1,2 +1,3 @@
load 785753-1.html
load 785753-2.html
+load 1274044-1.html