mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1272781 - nsEscape should work with ns(C)Strings and not with char pointers, r=smaug
This commit is contained in:
parent
f5951cc1b7
commit
98894192c9
@ -5230,24 +5230,21 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
|
||||
// Create a URL to pass all the error information through to the page.
|
||||
|
||||
#undef SAFE_ESCAPE
|
||||
#define SAFE_ESCAPE(cstring, escArg1, escArg2) \
|
||||
{ \
|
||||
char* s = nsEscape(escArg1, escArg2); \
|
||||
if (!s) \
|
||||
return NS_ERROR_OUT_OF_MEMORY; \
|
||||
cstring.Adopt(s); \
|
||||
#define SAFE_ESCAPE(output, input, params) \
|
||||
if (NS_WARN_IF(!NS_Escape(input, output, params))) { \
|
||||
return NS_ERROR_OUT_OF_MEMORY; \
|
||||
}
|
||||
|
||||
nsCString escapedUrl, escapedCharset, escapedError, escapedDescription,
|
||||
escapedCSSClass;
|
||||
SAFE_ESCAPE(escapedUrl, url.get(), url_Path);
|
||||
SAFE_ESCAPE(escapedCharset, charset.get(), url_Path);
|
||||
SAFE_ESCAPE(escapedError,
|
||||
NS_ConvertUTF16toUTF8(aErrorType).get(), url_Path);
|
||||
SAFE_ESCAPE(escapedUrl, url, url_Path);
|
||||
SAFE_ESCAPE(escapedCharset, charset, url_Path);
|
||||
SAFE_ESCAPE(escapedError, NS_ConvertUTF16toUTF8(aErrorType), url_Path);
|
||||
SAFE_ESCAPE(escapedDescription,
|
||||
NS_ConvertUTF16toUTF8(aDescription).get(), url_Path);
|
||||
NS_ConvertUTF16toUTF8(aDescription), url_Path);
|
||||
if (aCSSClass) {
|
||||
SAFE_ESCAPE(escapedCSSClass, aCSSClass, url_Path);
|
||||
nsCString cssClass(aCSSClass);
|
||||
SAFE_ESCAPE(escapedCSSClass, cssClass, url_Path);
|
||||
}
|
||||
nsCString errorPageUrl("about:");
|
||||
errorPageUrl.AppendASCII(aErrorPage);
|
||||
@ -5276,9 +5273,7 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
|
||||
nsresult rv = GetAppManifestURL(manifestURL);
|
||||
if (manifestURL.Length() > 0) {
|
||||
nsCString manifestParam;
|
||||
SAFE_ESCAPE(manifestParam,
|
||||
NS_ConvertUTF16toUTF8(manifestURL).get(),
|
||||
url_Path);
|
||||
SAFE_ESCAPE(manifestParam, NS_ConvertUTF16toUTF8(manifestURL), url_Path);
|
||||
errorPageUrl.AppendLiteral("&m=");
|
||||
errorPageUrl.AppendASCII(manifestParam.get());
|
||||
}
|
||||
|
@ -194,9 +194,9 @@ nsXHTMLContentSerializer::EscapeURI(nsIContent* aContent, const nsAString& aURI,
|
||||
if (textToSubURI && !IsASCII(part)) {
|
||||
rv = textToSubURI->ConvertAndEscape(mCharset.get(), part.get(), getter_Copies(escapedURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
else {
|
||||
escapedURI.Adopt(nsEscape(NS_ConvertUTF16toUTF8(part).get(), url_Path));
|
||||
} else if (NS_WARN_IF(!NS_Escape(NS_ConvertUTF16toUTF8(part), escapedURI,
|
||||
url_Path))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
AppendASCIItoUTF16(escapedURI, aEscapedURI);
|
||||
|
||||
@ -212,9 +212,9 @@ nsXHTMLContentSerializer::EscapeURI(nsIContent* aContent, const nsAString& aURI,
|
||||
if (textToSubURI) {
|
||||
rv = textToSubURI->ConvertAndEscape(mCharset.get(), part.get(), getter_Copies(escapedURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
else {
|
||||
escapedURI.Adopt(nsEscape(NS_ConvertUTF16toUTF8(part).get(), url_Path));
|
||||
} else if (NS_WARN_IF(!NS_Escape(NS_ConvertUTF16toUTF8(part), escapedURI,
|
||||
url_Path))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
AppendASCIItoUTF16(escapedURI, aEscapedURI);
|
||||
}
|
||||
|
@ -281,8 +281,10 @@ nsFSURLEncoded::GetEncodedSubmission(nsIURI* aURI,
|
||||
HandleMailtoSubject(path);
|
||||
|
||||
// Append the body to and force-plain-text args to the mailto line
|
||||
nsCString escapedBody;
|
||||
escapedBody.Adopt(nsEscape(mQueryString.get(), url_XAlphas));
|
||||
nsAutoCString escapedBody;
|
||||
if (NS_WARN_IF(!NS_Escape(mQueryString, escapedBody, url_XAlphas))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
path += NS_LITERAL_CSTRING("&force-plain-text=Y&body=") + escapedBody;
|
||||
|
||||
@ -666,11 +668,11 @@ nsFSTextPlain::GetEncodedSubmission(nsIURI* aURI,
|
||||
HandleMailtoSubject(path);
|
||||
|
||||
// Append the body to and force-plain-text args to the mailto line
|
||||
char* escapedBuf = nsEscape(NS_ConvertUTF16toUTF8(mBody).get(),
|
||||
url_XAlphas);
|
||||
NS_ENSURE_TRUE(escapedBuf, NS_ERROR_OUT_OF_MEMORY);
|
||||
nsCString escapedBody;
|
||||
escapedBody.Adopt(escapedBuf);
|
||||
nsAutoCString escapedBody;
|
||||
if (NS_WARN_IF(!NS_Escape(NS_ConvertUTF16toUTF8(mBody), escapedBody,
|
||||
url_XAlphas))) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
path += NS_LITERAL_CSTRING("&force-plain-text=Y&body=") + escapedBody;
|
||||
|
||||
|
@ -87,8 +87,7 @@ NS_IMETHODIMP nsTextToSubURI::ConvertAndEscape(
|
||||
outlen += finLen;
|
||||
}
|
||||
}
|
||||
pBuf[outlen] = '\0';
|
||||
*_retval = nsEscape(pBuf, url_XPAlphas);
|
||||
*_retval = nsEscape(pBuf, outlen, nullptr, url_XPAlphas);
|
||||
if (nullptr == *_retval) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -269,24 +269,28 @@ nsDirectoryIndexStream::Read(char* aBuf, uint32_t aCount, uint32_t* aReadCount)
|
||||
mBuf.AppendLiteral("201: ");
|
||||
|
||||
// The "filename" field
|
||||
char* escaped = nullptr;
|
||||
if (!NS_IsNativeUTF8()) {
|
||||
nsAutoString leafname;
|
||||
rv = current->GetLeafName(leafname);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!leafname.IsEmpty())
|
||||
escaped = nsEscape(NS_ConvertUTF16toUTF8(leafname).get(), url_Path);
|
||||
|
||||
nsAutoCString escaped;
|
||||
if (!leafname.IsEmpty() &&
|
||||
NS_Escape(NS_ConvertUTF16toUTF8(leafname), escaped, url_Path)) {
|
||||
mBuf.Append(escaped);
|
||||
mBuf.Append(' ');
|
||||
}
|
||||
} else {
|
||||
nsAutoCString leafname;
|
||||
rv = current->GetNativeLeafName(leafname);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!leafname.IsEmpty())
|
||||
escaped = nsEscape(leafname.get(), url_Path);
|
||||
}
|
||||
if (escaped) {
|
||||
mBuf += escaped;
|
||||
mBuf.Append(' ');
|
||||
free(escaped);
|
||||
|
||||
nsAutoCString escaped;
|
||||
if (!leafname.IsEmpty() &&
|
||||
NS_Escape(leafname, escaped, url_Path)) {
|
||||
mBuf.Append(escaped);
|
||||
mBuf.Append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
// The "content-length" field
|
||||
|
@ -307,9 +307,9 @@ nsFTPDirListingConv::DigestBufferLines(char *aBuffer, nsCString &aString) {
|
||||
PR_FormatTimeUSEnglish(buffer, sizeof(buffer),
|
||||
"%a, %d %b %Y %H:%M:%S", &result.fe_time );
|
||||
|
||||
char *escapedDate = nsEscape(buffer, url_Path);
|
||||
aString.Append(escapedDate);
|
||||
free(escapedDate);
|
||||
nsAutoCString escaped;
|
||||
NS_WARN_IF(!NS_Escape(nsDependentCString(buffer), escaped, url_Path));
|
||||
aString.Append(escaped);
|
||||
aString.Append(' ');
|
||||
|
||||
// ENTRY TYPE
|
||||
|
@ -1007,16 +1007,14 @@ FileSystemDataSource::GetFolderList(nsIRDFResource *source, bool allowHidden,
|
||||
fullURI.Append('/');
|
||||
}
|
||||
|
||||
char *escLeafStr = nsEscape(NS_ConvertUTF16toUTF8(leafStr).get(), url_Path);
|
||||
nsAutoCString leaf;
|
||||
bool escaped = NS_Escape(NS_ConvertUTF16toUTF8(leafStr), leaf, url_Path);
|
||||
leafStr.Truncate();
|
||||
|
||||
if (!escLeafStr)
|
||||
if (!escaped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsAutoCString leaf(escLeafStr);
|
||||
free(escLeafStr);
|
||||
escLeafStr = nullptr;
|
||||
|
||||
// using nsEscape() [above] doesn't escape slashes, so do that by hand
|
||||
int32_t aOffset;
|
||||
while ((aOffset = leaf.FindChar('/')) >= 0)
|
||||
|
@ -74,20 +74,8 @@ AppendPercentHex(char16_t* aBuffer, char16_t aChar)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
char*
|
||||
nsEscape(const char* aStr, nsEscapeMask aFlags)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!aStr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nsEscapeWithLength(aStr, strlen(aStr), nullptr, aFlags);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
char*
|
||||
nsEscapeWithLength(const char* aStr, size_t aLength, size_t* aOutputLength,
|
||||
nsEscapeMask aFlags)
|
||||
nsEscape(const char* aStr, size_t aLength, size_t* aOutputLength,
|
||||
nsEscapeMask aFlags)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!aStr) {
|
||||
|
@ -38,18 +38,10 @@ extern "C" {
|
||||
* @param aMask How to escape the string
|
||||
* @return A newly allocated escaped string that must be free'd with
|
||||
* nsCRT::free, or null on failure
|
||||
* @note: Please, don't use this function. Use NS_Escape instead!
|
||||
*/
|
||||
char* nsEscapeWithLength(const char* aStr, size_t aLength, size_t* aOutputLen,
|
||||
nsEscapeMask aMask);
|
||||
|
||||
/**
|
||||
* Escape the given string according to mask
|
||||
* @param aStr The string to escape
|
||||
* @param aMask How to escape the string
|
||||
* @return A newly allocated escaped string that must be free'd with
|
||||
* nsCRT::free, or null on failure
|
||||
*/
|
||||
char* nsEscape(const char* aStr, nsEscapeMask aMask);
|
||||
char* nsEscape(const char* aStr, size_t aLength, size_t* aOutputLen,
|
||||
nsEscapeMask aMask);
|
||||
|
||||
char* nsUnescape(char* aStr);
|
||||
/* decode % escaped hex codes into character values,
|
||||
@ -201,8 +193,8 @@ NS_Escape(const nsACString& aOriginal, nsACString& aEscaped,
|
||||
nsEscapeMask aMask)
|
||||
{
|
||||
size_t escLen = 0;
|
||||
char* esc = nsEscapeWithLength(aOriginal.BeginReading(), aOriginal.Length(),
|
||||
&escLen, aMask);
|
||||
char* esc = nsEscape(aOriginal.BeginReading(), aOriginal.Length(), &escLen,
|
||||
aMask);
|
||||
if (! esc) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user