зеркало из https://github.com/mozilla/gecko-dev.git
Bug 991471 - Fix offset when setting host on URL. r=mcmanus
This commit is contained in:
Родитель
8fcbd56508
Коммит
cf4f80d9e4
|
@ -1507,7 +1507,14 @@ nsStandardURL::SetHost(const nsACString &input)
|
|||
len = flat.Length();
|
||||
|
||||
if (mHost.mLen < 0) {
|
||||
mHost.mPos = mAuthority.mPos;
|
||||
int port_length = 0;
|
||||
if (mPort != -1) {
|
||||
nsAutoCString buf;
|
||||
buf.Assign(':');
|
||||
buf.AppendInt(mPort);
|
||||
port_length = buf.Length();
|
||||
}
|
||||
mHost.mPos = mAuthority.mPos + mAuthority.mLen - port_length;
|
||||
mHost.mLen = 0;
|
||||
}
|
||||
|
||||
|
@ -1551,7 +1558,7 @@ nsStandardURL::SetPort(int32_t port)
|
|||
nsAutoCString buf;
|
||||
buf.Assign(':');
|
||||
buf.AppendInt(port);
|
||||
mSpec.Insert(buf, mHost.mPos + mHost.mLen);
|
||||
mSpec.Insert(buf, mAuthority.mPos + mAuthority.mLen);
|
||||
mAuthority.mLen += buf.Length();
|
||||
ShiftFromPath(buf.Length());
|
||||
}
|
||||
|
@ -1559,9 +1566,14 @@ nsStandardURL::SetPort(int32_t port)
|
|||
// Don't allow mPort == mDefaultPort
|
||||
port = -1;
|
||||
|
||||
// compute length of the current port
|
||||
nsAutoCString buf;
|
||||
buf.Assign(':');
|
||||
buf.AppendInt(mPort);
|
||||
|
||||
// need to remove the port number from the URL spec
|
||||
uint32_t start = mHost.mPos + mHost.mLen;
|
||||
int32_t lengthToCut = mPath.mPos - start;
|
||||
uint32_t start = mAuthority.mPos + mAuthority.mLen - buf.Length();
|
||||
int32_t lengthToCut = buf.Length();
|
||||
mSpec.Cut(start, lengthToCut);
|
||||
mAuthority.mLen -= lengthToCut;
|
||||
ShiftFromPath(-lengthToCut);
|
||||
|
@ -1569,9 +1581,13 @@ nsStandardURL::SetPort(int32_t port)
|
|||
else {
|
||||
// need to replace the existing port
|
||||
nsAutoCString buf;
|
||||
buf.Assign(':');
|
||||
buf.AppendInt(mPort);
|
||||
uint32_t start = mAuthority.mPos + mAuthority.mLen - buf.Length();
|
||||
uint32_t length = buf.Length();
|
||||
|
||||
buf.Assign(':');
|
||||
buf.AppendInt(port);
|
||||
uint32_t start = mHost.mPos + mHost.mLen + 1;
|
||||
uint32_t length = mPath.mPos - start;
|
||||
mSpec.Replace(start, length, buf);
|
||||
if (buf.Length() != length) {
|
||||
mAuthority.mLen += buf.Length() - length;
|
||||
|
|
Загрузка…
Ссылка в новой задаче