mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 17:23:59 +00:00
Backed out bug 125608 because of orange.
This commit is contained in:
parent
a0d81f4d6b
commit
82bae5057c
@ -177,8 +177,7 @@ nsSegmentEncoder::EncodeSegmentCount(const char *str,
|
||||
const URLSegment &seg,
|
||||
PRInt16 mask,
|
||||
nsAFlatCString &result,
|
||||
PRBool &appended,
|
||||
PRUint32 extraLen)
|
||||
PRBool &appended)
|
||||
{
|
||||
appended = PR_FALSE;
|
||||
if (!str)
|
||||
@ -221,8 +220,6 @@ nsSegmentEncoder::EncodeSegmentCount(const char *str,
|
||||
len = encBuf.Length();
|
||||
appended = PR_TRUE;
|
||||
}
|
||||
|
||||
len += extraLen;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
@ -501,19 +498,16 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
||||
encBasename, encExtension, encParam, encQuery, encRef;
|
||||
PRBool useEncUsername, useEncPassword, useEncHost, useEncDirectory,
|
||||
useEncBasename, useEncExtension, useEncParam, useEncQuery, useEncRef;
|
||||
nsCAutoString portbuf;
|
||||
|
||||
//
|
||||
// escape each URL segment, if necessary, and calculate approximate normalized
|
||||
// spec length.
|
||||
//
|
||||
// [scheme://][username[:password]@]host[:port]/path[;param][?query_string][#ref]
|
||||
|
||||
PRUint32 approxLen = 0;
|
||||
PRUint32 approxLen = 3; // includes room for "://"
|
||||
|
||||
// the scheme is already ASCII
|
||||
if (mScheme.mLen > 0)
|
||||
approxLen += mScheme.mLen + 3; // includes room for "://";
|
||||
approxLen += mScheme.mLen;
|
||||
|
||||
// encode URL segments; convert UTF-8 to origin charset and possibly escape.
|
||||
// results written to encXXX variables only if |spec| is not already in the
|
||||
@ -521,31 +515,14 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
||||
{
|
||||
GET_SEGMENT_ENCODER(encoder);
|
||||
GET_QUERY_ENCODER(queryEncoder);
|
||||
// Username@
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mUsername, esc_Username, encUsername, useEncUsername,1);
|
||||
// :Password
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mPassword, esc_Password, encPassword, useEncPassword,1);
|
||||
// mHost is handled differently below due to encoding differences
|
||||
NS_ABORT_IF_FALSE(mPort > 0 || mPort == -1, "Invalid negative mPort");
|
||||
if (mPort != -1 && mPort != mDefaultPort)
|
||||
{
|
||||
// :port
|
||||
portbuf.AppendInt(mPort);
|
||||
approxLen += portbuf.Length() + 1;
|
||||
}
|
||||
|
||||
approxLen += 1; // reserve space for possible leading '/' - may not be needed
|
||||
// Should just use mPath? These are pessimistic, and thus waste space
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mDirectory, esc_Directory, encDirectory, useEncDirectory,1);
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mUsername, esc_Username, encUsername, useEncUsername);
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mPassword, esc_Password, encPassword, useEncPassword);
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mDirectory, esc_Directory, encDirectory, useEncDirectory);
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mBasename, esc_FileBaseName, encBasename, useEncBasename);
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mExtension, esc_FileExtension, encExtension, useEncExtension,1);
|
||||
|
||||
// ;param
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mParam, esc_Param, encParam, useEncParam,1);
|
||||
// ?query
|
||||
approxLen += queryEncoder.EncodeSegmentCount(spec, mQuery, esc_Query, encQuery, useEncQuery,1);
|
||||
// #ref
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mRef, esc_Ref, encRef, useEncRef,1);
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mExtension, esc_FileExtension, encExtension, useEncExtension);
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mParam, esc_Param, encParam, useEncParam);
|
||||
approxLen += queryEncoder.EncodeSegmentCount(spec, mQuery, esc_Query, encQuery, useEncQuery);
|
||||
approxLen += encoder.EncodeSegmentCount(spec, mRef, esc_Ref, encRef, useEncRef);
|
||||
}
|
||||
|
||||
// do not escape the hostname, if IPv6 address literal, mHost will
|
||||
@ -568,8 +545,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
||||
//
|
||||
// generate the normalized URL string
|
||||
//
|
||||
// approxLen should be correct or 1 high
|
||||
if (!EnsureStringLength(mSpec, approxLen+1)) // buf needs a trailing '\0' below
|
||||
if (!EnsureStringLength(mSpec, approxLen + 32))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
char *buf;
|
||||
mSpec.BeginWriting(buf);
|
||||
@ -596,10 +572,10 @@ 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");
|
||||
if (mPort != -1 && mPort != mDefaultPort) {
|
||||
nsCAutoString portbuf;
|
||||
portbuf.AppendInt(mPort);
|
||||
buf[i++] = ':';
|
||||
// Already formatted while building approxLen
|
||||
i = AppendToBuf(buf, i, portbuf.get(), portbuf.Length());
|
||||
}
|
||||
}
|
||||
@ -687,7 +663,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
|
||||
CoalescePath(coalesceFlag, buf + mDirectory.mPos);
|
||||
}
|
||||
mSpec.SetLength(strlen(buf));
|
||||
NS_ASSERTION(mSpec.Length() <= approxLen, "We've overflowed the mSpec buffer!");
|
||||
NS_ASSERTION(mSpec.Length() <= approxLen+32, "We've overflowed the mSpec buffer!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -135,8 +135,7 @@ public: /* internal -- HPUX compiler can't handle this being private */
|
||||
const URLSegment &segment,
|
||||
PRInt16 mask,
|
||||
nsAFlatCString &buf,
|
||||
PRBool& appended,
|
||||
PRUint32 extraLen = 0);
|
||||
PRBool& appended);
|
||||
|
||||
// Encode the given string if necessary, and return a reference to
|
||||
// the encoded string. Returns a reference to |buf| if encoding
|
||||
|
Loading…
Reference in New Issue
Block a user