mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Make SetPort actually update the internal offsets correctly. Bug 388281, r+sr=biesi
This commit is contained in:
parent
87d559dd76
commit
28323d5173
@ -1511,13 +1511,16 @@ nsStandardURL::SetPort(PRInt32 port)
|
||||
buf.Assign(':');
|
||||
buf.AppendInt(port);
|
||||
mSpec.Insert(buf, mHost.mPos + mHost.mLen);
|
||||
mAuthority.mLen += buf.Length();
|
||||
ShiftFromPath(buf.Length());
|
||||
}
|
||||
else if (port == -1) {
|
||||
else if (port == -1 || port == mDefaultPort) {
|
||||
// need to remove the port number from the URL spec
|
||||
PRUint32 start = mHost.mPos + mHost.mLen;
|
||||
mSpec.Cut(start, mPath.mPos - start);
|
||||
ShiftFromPath(start - mPath.mPos);
|
||||
PRUint32 lengthToCut = mPath.mPos - start;
|
||||
mSpec.Cut(start, lengthToCut);
|
||||
mAuthority.mLen -= lengthToCut;
|
||||
ShiftFromPath(-lengthToCut);
|
||||
}
|
||||
else {
|
||||
// need to replace the existing port
|
||||
@ -1526,8 +1529,10 @@ nsStandardURL::SetPort(PRInt32 port)
|
||||
PRUint32 start = mHost.mPos + mHost.mLen + 1;
|
||||
PRUint32 length = mPath.mPos - start;
|
||||
mSpec.Replace(start, length, buf);
|
||||
if (buf.Length() != length)
|
||||
if (buf.Length() != length) {
|
||||
mAuthority.mLen += buf.Length() - length;
|
||||
ShiftFromPath(buf.Length() - length);
|
||||
}
|
||||
}
|
||||
|
||||
mPort = port;
|
||||
|
27
netwerk/test/unit/test_bug388281.js
Normal file
27
netwerk/test/unit/test_bug388281.js
Normal file
@ -0,0 +1,27 @@
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
function run_test() {
|
||||
const ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
|
||||
var uri = ios.newURI("http://foo.com/file.txt", null, null);
|
||||
uri.port = 90;
|
||||
do_check_eq(uri.hostPort, "foo.com:90");
|
||||
|
||||
uri = ios.newURI("http://foo.com:10/file.txt", null, null);
|
||||
uri.port = 500;
|
||||
do_check_eq(uri.hostPort, "foo.com:500");
|
||||
|
||||
uri = ios.newURI("http://foo.com:5000/file.txt", null, null);
|
||||
uri.port = 20;
|
||||
do_check_eq(uri.hostPort, "foo.com:20");
|
||||
|
||||
uri = ios.newURI("http://foo.com:5000/file.txt", null, null);
|
||||
uri.port = -1;
|
||||
do_check_eq(uri.hostPort, "foo.com");
|
||||
|
||||
uri = ios.newURI("http://foo.com:5000/file.txt", null, null);
|
||||
uri.port = 80;
|
||||
do_check_eq(uri.hostPort, "foo.com");
|
||||
}
|
Loading…
Reference in New Issue
Block a user