From 24d305ffb0bb456e9b7dce24ead7bced1b308e39 Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Thu, 26 May 2011 00:26:31 -0400 Subject: [PATCH] Backed out changeset 369680a6f40b - apparent blown merge --- netwerk/base/src/nsStandardURL.cpp | 51 ++++++++---------------------- netwerk/base/src/nsStandardURL.h | 3 +- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/netwerk/base/src/nsStandardURL.cpp b/netwerk/base/src/nsStandardURL.cpp index d6a5f684cb9e..2f08b8af51cf 100644 --- a/netwerk/base/src/nsStandardURL.cpp +++ b/netwerk/base/src/nsStandardURL.cpp @@ -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,30 +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 - 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 @@ -567,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,8 +573,9 @@ nsStandardURL::BuildNormalizedSpec(const char *spec) i = AppendSegmentToBuf(buf, i, spec, mHost, &encHost, useEncHost); net_ToLowerCase(buf + mHost.mPos, mHost.mLen); 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()); } } @@ -685,8 +663,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec) CoalescePath(coalesceFlag, buf + mDirectory.mPos); } mSpec.SetLength(strlen(buf)); - LOG(("BuildNormalizedSpec: %s (len %d : approxLen %d - saved %d)",buf,strlen(buf),approxLen,old_approxLen+32 - approxLen)); - 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; } diff --git a/netwerk/base/src/nsStandardURL.h b/netwerk/base/src/nsStandardURL.h index 5d27cc2245c1..cc774a8161ed 100644 --- a/netwerk/base/src/nsStandardURL.h +++ b/netwerk/base/src/nsStandardURL.h @@ -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