mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1389251 - Add esc_Spaces that may be used to force escaping of spaces r=bz,jdescottes
MozReview-Commit-ID: 4tahH3IOKW --HG-- extra : rebase_source : 12057b98c87d7d3c57e90888082f540c49c5a9a9
This commit is contained in:
parent
6444ab9d1e
commit
4cade1b2b5
@ -393,7 +393,7 @@ SpeechDispatcherService::Setup()
|
||||
|
||||
uri.AssignLiteral(URI_PREFIX);
|
||||
nsAutoCString name;
|
||||
NS_EscapeURL(list[i]->name, -1, esc_OnlyNonASCII | esc_AlwaysCopy, name);
|
||||
NS_EscapeURL(list[i]->name, -1, esc_OnlyNonASCII | esc_Spaces | esc_AlwaysCopy, name);
|
||||
uri.Append(NS_ConvertUTF8toUTF16(name));;
|
||||
uri.AppendLiteral("?");
|
||||
|
||||
|
@ -512,7 +512,7 @@ nsresult
|
||||
nsSimpleURI::SetRef(const nsACString &aRef)
|
||||
{
|
||||
nsAutoCString ref;
|
||||
nsresult rv = NS_EscapeURL(aRef, esc_OnlyNonASCII, ref, fallible);
|
||||
nsresult rv = NS_EscapeURL(aRef, esc_OnlyNonASCII | esc_Spaces, ref, fallible);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ InterceptedHttpChannel::FollowSyntheticRedirect()
|
||||
|
||||
// make sure non-ASCII characters in the location header are escaped.
|
||||
nsAutoCString locationBuf;
|
||||
if (NS_EscapeURL(location.get(), -1, esc_OnlyNonASCII, locationBuf)) {
|
||||
if (NS_EscapeURL(location.get(), -1, esc_OnlyNonASCII | esc_Spaces, locationBuf)) {
|
||||
location = locationBuf;
|
||||
}
|
||||
|
||||
|
@ -992,7 +992,7 @@ nsHttpChannel::SetupTransaction()
|
||||
}
|
||||
|
||||
// path may contain UTF-8 characters, so ensure that they're escaped.
|
||||
if (NS_EscapeURL(path.get(), path.Length(), esc_OnlyNonASCII, buf)) {
|
||||
if (NS_EscapeURL(path.get(), path.Length(), esc_OnlyNonASCII | esc_Spaces, buf)) {
|
||||
requestURI = &buf;
|
||||
} else {
|
||||
requestURI = &path;
|
||||
@ -5503,7 +5503,7 @@ nsHttpChannel::AsyncProcessRedirection(uint32_t redirectType)
|
||||
|
||||
// make sure non-ASCII characters in the location header are escaped.
|
||||
nsAutoCString locationBuf;
|
||||
if (NS_EscapeURL(location.get(), -1, esc_OnlyNonASCII, locationBuf))
|
||||
if (NS_EscapeURL(location.get(), -1, esc_OnlyNonASCII | esc_Spaces, locationBuf))
|
||||
location = locationBuf;
|
||||
|
||||
mRedirectType = redirectType;
|
||||
|
@ -112,7 +112,7 @@ nsHttpDigestAuth::GetMethodAndPath(nsIHttpAuthenticableChannel *authChannel,
|
||||
// instead of regenerating it here.
|
||||
//
|
||||
nsAutoCString buf;
|
||||
rv = NS_EscapeURL(path, esc_OnlyNonASCII, buf, mozilla::fallible);
|
||||
rv = NS_EscapeURL(path, esc_OnlyNonASCII | esc_Spaces, buf, mozilla::fallible);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
path = buf;
|
||||
}
|
||||
|
@ -594,11 +594,26 @@ function check_nested_mutations()
|
||||
do_check_uri_eq(uri3, uri1);
|
||||
}
|
||||
|
||||
function check_space_escaping()
|
||||
{
|
||||
let uri = gIoService.newURI("data:text/plain,hello%20world#space hash");
|
||||
Assert.equal(uri.spec, "data:text/plain,hello%20world#space%20hash");
|
||||
uri = gIoService.newURI("data:text/plain,hello%20world#space%20hash");
|
||||
Assert.equal(uri.spec, "data:text/plain,hello%20world#space%20hash");
|
||||
uri = gIoService.newURI("data:text/plain,hello world#space%20hash");
|
||||
Assert.equal(uri.spec, "data:text/plain,hello world#space%20hash");
|
||||
uri = gIoService.newURI("data:text/plain,hello world#space hash");
|
||||
Assert.equal(uri.spec, "data:text/plain,hello world#space%20hash");
|
||||
uri = gIoService.newURI("http://example.com/test path#test path");
|
||||
uri = gIoService.newURI("http://example.com/test%20path#test%20path");
|
||||
}
|
||||
|
||||
// TEST MAIN FUNCTION
|
||||
// ------------------
|
||||
function run_test()
|
||||
{
|
||||
check_nested_mutations();
|
||||
check_space_escaping();
|
||||
|
||||
// UTF-8 check - From bug 622981
|
||||
// ASCII
|
||||
|
@ -319,6 +319,7 @@ T_EscapeURL(const typename T::char_type* aPart, size_t aPartLen,
|
||||
bool ignoreAscii = !!(aFlags & esc_OnlyNonASCII);
|
||||
bool writing = !!(aFlags & esc_AlwaysCopy);
|
||||
bool colon = !!(aFlags & esc_Colon);
|
||||
bool spaces = !!(aFlags & esc_Spaces);
|
||||
|
||||
auto src = reinterpret_cast<const unsigned_char_type*>(aPart);
|
||||
|
||||
@ -361,6 +362,7 @@ T_EscapeURL(const typename T::char_type* aPart, size_t aPartLen,
|
||||
|| (c > 0x7f && ignoreNonAscii)
|
||||
|| (c >= 0x20 && c < 0x7f && ignoreAscii))
|
||||
&& !(c == ':' && colon)
|
||||
&& !(c == ' ' && spaces)
|
||||
&& !(previousIsNonASCII && c == '|' && !ignoreNonAscii)) {
|
||||
if (writing) {
|
||||
tempBuffer[tempBufferPos++] = c;
|
||||
|
@ -93,7 +93,8 @@ enum EscapeMask {
|
||||
* ascii octets (<= 0x7F) to be skipped when unescaping */
|
||||
esc_AlwaysCopy = 1u << 13, /* copy input to result buf even if escaping is unnecessary */
|
||||
esc_Colon = 1u << 14, /* forces escape of colon */
|
||||
esc_SkipControl = 1u << 15 /* skips C0 and DEL from unescaping */
|
||||
esc_SkipControl = 1u << 15, /* skips C0 and DEL from unescaping */
|
||||
esc_Spaces = 1u << 16 /* forces escape of spaces */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -133,3 +133,19 @@ TEST(Escape, nsAppendEscapedHTML)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Escape, EscapeSpaces)
|
||||
{
|
||||
// Tests the fallible version of NS_EscapeURL works as expected when no
|
||||
// escaping is necessary.
|
||||
nsCString toEscape("data:\x0D\x0A spa ces\xC4\x9F");
|
||||
nsCString escaped;
|
||||
nsresult rv = NS_EscapeURL(toEscape, esc_OnlyNonASCII, escaped, fallible);
|
||||
EXPECT_EQ(rv, NS_OK);
|
||||
// Only non-ASCII and C0
|
||||
EXPECT_STREQ(escaped.BeginReading(), "data:%0D%0A spa ces%C4%9F");
|
||||
|
||||
escaped.Truncate();
|
||||
rv = NS_EscapeURL(toEscape, esc_OnlyNonASCII | esc_Spaces, escaped, fallible);
|
||||
EXPECT_EQ(rv, NS_OK);
|
||||
EXPECT_STREQ(escaped.BeginReading(), "data:%0D%0A%20spa%20ces%C4%9F");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user