mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 20:01:50 +00:00
Bug 930450 - Setting port to the empty string should set URL's port to the default value. Setting it to "0" should set URL's port to 0., r=bz, r=honzab
This commit is contained in:
parent
60eb19e15a
commit
f98a8d58d2
@ -26,17 +26,27 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=930450
|
||||
var url = new URL('http://www.example.com:8080');
|
||||
is(url.port, 8080, 'URL.port is 8080');
|
||||
url.port = '';
|
||||
is(url.port, 0, 'URL.port is 0');
|
||||
ise(url.port, '', 'URL.port is \'\'');
|
||||
url.port = 0;
|
||||
ise(url.port, '0', 'URL.port is 0');
|
||||
|
||||
var link = document.getElementById("link");
|
||||
is(link.port, 8080, 'URL.port is 8080');
|
||||
link.port = '';
|
||||
is(link.port, 0, 'URL.port is 0');
|
||||
is(link.href, 'http://www.example.com/', "link.href matches");
|
||||
ise(link.port, '', 'URL.port is \'\'');
|
||||
link.port = 0;
|
||||
is(link.href, 'http://www.example.com:0/', "link.href matches");
|
||||
ise(link.port, '0', 'URL.port is 0');
|
||||
|
||||
var area = document.getElementById("area");
|
||||
is(area.port, 8080, 'URL.port is 8080');
|
||||
area.port = '';
|
||||
is(area.port, 0, 'URL.port is 0');
|
||||
is(area.href, 'http://www.example.com/', "area.href matches");
|
||||
ise(area.port, '', 'URL.port is \'\'');
|
||||
area.port = 0;
|
||||
is(area.href, 'http://www.example.com:0/', "area.href matches");
|
||||
ise(area.port, '0', 'URL.port is 0');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
@ -765,6 +765,11 @@ nsIOService::AllowPort(int32_t inPort, const char *scheme, bool *_retval)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (port == 0) {
|
||||
*_retval = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// first check to see if the port is in our blacklist:
|
||||
int32_t badPortListCnt = mRestrictedPortList.Length();
|
||||
for (int i=0; i<badPortListCnt; i++)
|
||||
|
@ -515,7 +515,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
||||
if (mPassword.mLen >= 0)
|
||||
approxLen += 1 + encoder.EncodeSegmentCount(spec, mPassword, esc_Password, encPassword, useEncPassword);
|
||||
// mHost is handled differently below due to encoding differences
|
||||
NS_ABORT_IF_FALSE(mPort > 0 || mPort == -1, "Invalid negative mPort");
|
||||
NS_ABORT_IF_FALSE(mPort >= -1, "Invalid negative mPort");
|
||||
if (mPort != -1 && mPort != mDefaultPort)
|
||||
{
|
||||
// :port
|
||||
@ -588,7 +588,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
||||
if (mHost.mLen > 0) {
|
||||
i = AppendSegmentToBuf(buf, i, spec, mHost, &encHost, useEncHost);
|
||||
net_ToLowerCase(buf + mHost.mPos, mHost.mLen);
|
||||
NS_ABORT_IF_FALSE(mPort > 0 || mPort == -1, "Invalid negative mPort");
|
||||
NS_ABORT_IF_FALSE(mPort >= -1, "Invalid negative mPort");
|
||||
if (mPort != -1 && mPort != mDefaultPort) {
|
||||
buf[i++] = ':';
|
||||
// Already formatted while building approxLen
|
||||
@ -1529,8 +1529,8 @@ nsStandardURL::SetPort(int32_t port)
|
||||
if ((port == mPort) || (mPort == -1 && port == mDefaultPort))
|
||||
return NS_OK;
|
||||
|
||||
// ports must be >= 0 (and 0 is pretty much garbage too, though legal per RFC)
|
||||
if (port <= 0 && port != -1) // -1 == use default
|
||||
// ports must be >= 0
|
||||
if (port < -1) // -1 == use default
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
|
||||
if (mURLType == URLTYPE_NO_AUTHORITY) {
|
||||
|
@ -579,7 +579,7 @@ nsAuthURLParser::ParseServerInfo(const char *serverinfo, int32_t serverinfoLen,
|
||||
|
||||
nsresult err;
|
||||
*port = buf.ToInteger(&err);
|
||||
if (NS_FAILED(err) || *port <= 0)
|
||||
if (NS_FAILED(err) || *port < 0)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ function run_test() {
|
||||
test_port(":invalid", true);
|
||||
test_port(":-2", true);
|
||||
test_port(":-1", true);
|
||||
test_port(":0", true);
|
||||
test_port(":0", false);
|
||||
test_port(":185891548721348172817857824356013651809236172635716571865023757816234081723451516780356", true);
|
||||
|
||||
// Following 3 tests are all failing, we do not throw, although we parse the whole string and use only 5870 as a portnumber
|
||||
|
Loading…
x
Reference in New Issue
Block a user