| Index: net/base/escape_unittest.cc
|
| diff --git a/net/base/escape_unittest.cc b/net/base/escape_unittest.cc
|
| index 4d3bcbdd40c029025f0881c9b102e5bd4e80b344..640b29567b829fa99536c585241e98c02c41cba9 100644
|
| --- a/net/base/escape_unittest.cc
|
| +++ b/net/base/escape_unittest.cc
|
| @@ -59,20 +59,14 @@ struct EscapeForHTMLCase {
|
|
|
| TEST(EscapeTest, EscapeTextForFormSubmission) {
|
| const EscapeCase escape_cases[] = {
|
| - {"foo", "foo"},
|
| - {"foo bar", "foo+bar"},
|
| - {"foo++", "foo%2B%2B"}
|
| - };
|
| + {"foo", "foo"}, {"foo bar", "foo+bar"}, {"foo++", "foo%2B%2B"}};
|
| for (size_t i = 0; i < arraysize(escape_cases); ++i) {
|
| EscapeCase value = escape_cases[i];
|
| EXPECT_EQ(value.output, EscapeQueryParamValue(value.input, true));
|
| }
|
|
|
| const EscapeCase escape_cases_no_plus[] = {
|
| - {"foo", "foo"},
|
| - {"foo bar", "foo%20bar"},
|
| - {"foo++", "foo%2B%2B"}
|
| - };
|
| + {"foo", "foo"}, {"foo bar", "foo%20bar"}, {"foo++", "foo%2B%2B"}};
|
| for (size_t i = 0; i < arraysize(escape_cases_no_plus); ++i) {
|
| EscapeCase value = escape_cases_no_plus[i];
|
| EXPECT_EQ(value.output, EscapeQueryParamValue(value.input, false));
|
| @@ -80,10 +74,10 @@ TEST(EscapeTest, EscapeTextForFormSubmission) {
|
|
|
| // Test all the values in we're supposed to be escaping.
|
| const std::string no_escape(
|
| - "abcdefghijklmnopqrstuvwxyz"
|
| - "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| - "0123456789"
|
| - "!'()*-._~");
|
| + "abcdefghijklmnopqrstuvwxyz"
|
| + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| + "0123456789"
|
| + "!'()*-._~");
|
| for (int i = 0; i < 256; ++i) {
|
| std::string in;
|
| in.push_back(i);
|
| @@ -106,17 +100,17 @@ TEST(EscapeTest, EscapeTextForFormSubmission) {
|
|
|
| TEST(EscapeTest, EscapePath) {
|
| ASSERT_EQ(
|
| - // Most of the character space we care about, un-escaped
|
| - EscapePath(
|
| - "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;"
|
| - "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| - "[\\]^_`abcdefghijklmnopqrstuvwxyz"
|
| - "{|}~\x7f\x80\xff"),
|
| - // Escaped
|
| - "%02%0A%1D%20!%22%23$%25&'()*+,-./0123456789%3A;"
|
| - "%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| - "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz"
|
| - "%7B%7C%7D~%7F%80%FF");
|
| + // Most of the character space we care about, un-escaped
|
| + EscapePath(
|
| + "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;"
|
| + "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| + "[\\]^_`abcdefghijklmnopqrstuvwxyz"
|
| + "{|}~\x7f\x80\xff"),
|
| + // Escaped
|
| + "%02%0A%1D%20!%22%23$%25&'()*+,-./0123456789%3A;"
|
| + "%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| + "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz"
|
| + "%7B%7C%7D~%7F%80%FF");
|
| }
|
|
|
| TEST(EscapeTest, DataURLWithAccentedCharacters) {
|
| @@ -131,17 +125,18 @@ TEST(EscapeTest, DataURLWithAccentedCharacters) {
|
|
|
| TEST(EscapeTest, EscapeUrlEncodedData) {
|
| ASSERT_EQ(
|
| - // Most of the character space we care about, un-escaped
|
| - EscapeUrlEncodedData(
|
| - "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;"
|
| - "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| - "[\\]^_`abcdefghijklmnopqrstuvwxyz"
|
| - "{|}~\x7f\x80\xff", true),
|
| - // Escaped
|
| - "%02%0A%1D+!%22%23%24%25%26%27()*%2B,-./0123456789:%3B"
|
| - "%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| - "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz"
|
| - "%7B%7C%7D~%7F%80%FF");
|
| + // Most of the character space we care about, un-escaped
|
| + EscapeUrlEncodedData(
|
| + "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;"
|
| + "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| + "[\\]^_`abcdefghijklmnopqrstuvwxyz"
|
| + "{|}~\x7f\x80\xff",
|
| + true),
|
| + // Escaped
|
| + "%02%0A%1D+!%22%23%24%25%26%27()*%2B,-./0123456789:%3B"
|
| + "%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
| + "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz"
|
| + "%7B%7C%7D~%7F%80%FF");
|
| }
|
|
|
| TEST(EscapeTest, EscapeUrlEncodedDataSpace) {
|
| @@ -151,41 +146,50 @@ TEST(EscapeTest, EscapeUrlEncodedDataSpace) {
|
|
|
| TEST(EscapeTest, UnescapeURLComponentASCII) {
|
| const UnescapeURLCaseASCII unescape_cases[] = {
|
| - {"", UnescapeRule::NORMAL, ""},
|
| - {"%2", UnescapeRule::NORMAL, "%2"},
|
| - {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"},
|
| - {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"},
|
| - {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"},
|
| - {"Some%20random text %25%2dOK", UnescapeRule::NONE,
|
| - "Some%20random text %25%2dOK"},
|
| - {"Some%20random text %25%2dOK", UnescapeRule::NORMAL,
|
| - "Some%20random text %25-OK"},
|
| - {"Some%20random text %25%2dOK", UnescapeRule::SPACES,
|
| - "Some random text %25-OK"},
|
| - {"Some%20random text %25%2dOK", UnescapeRule::URL_SPECIAL_CHARS,
|
| - "Some%20random text %-OK"},
|
| - {"Some%20random text %25%2dOK",
|
| - UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS,
|
| - "Some random text %-OK"},
|
| - {"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, "\xA0\xB1\xC2\xD3\xE4\xF5"},
|
| - {"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, "\xAa\xBb\xCc\xDd\xEe\xFf"},
|
| - // Certain URL-sensitive characters should not be unescaped unless asked.
|
| - {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::SPACES,
|
| - "Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"},
|
| - {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
|
| - UnescapeRule::URL_SPECIAL_CHARS,
|
| - "Hello%20%13%10world ## ?? == && %% ++"},
|
| - // We can neither escape nor unescape '@' since some websites expect it to
|
| - // be preserved as either '@' or "%40".
|
| - // See http://b/996720 and http://crbug.com/23933 .
|
| - {"me@my%40example", UnescapeRule::NORMAL, "me@my%40example"},
|
| - // Control characters.
|
| - {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::URL_SPECIAL_CHARS,
|
| - "%01%02%03%04%05%06%07%08%09 %"},
|
| - {"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::CONTROL_CHARS,
|
| - "\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"},
|
| - {"Hello%20%13%10%02", UnescapeRule::SPACES, "Hello %13%10%02"},
|
| - {"Hello%20%13%10%02", UnescapeRule::CONTROL_CHARS, "Hello%20\x13\x10\x02"},
|
| + {"", UnescapeRule::NORMAL, ""},
|
| + {"%2", UnescapeRule::NORMAL, "%2"},
|
| + {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"},
|
| + {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"},
|
| + {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"},
|
| + {"Some%20random text %25%2dOK",
|
| + UnescapeRule::NONE,
|
| + "Some%20random text %25%2dOK"},
|
| + {"Some%20random text %25%2dOK",
|
| + UnescapeRule::NORMAL,
|
| + "Some%20random text %25-OK"},
|
| + {"Some%20random text %25%2dOK",
|
| + UnescapeRule::SPACES,
|
| + "Some random text %25-OK"},
|
| + {"Some%20random text %25%2dOK",
|
| + UnescapeRule::URL_SPECIAL_CHARS,
|
| + "Some%20random text %-OK"},
|
| + {"Some%20random text %25%2dOK",
|
| + UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS,
|
| + "Some random text %-OK"},
|
| + {"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, "\xA0\xB1\xC2\xD3\xE4\xF5"},
|
| + {"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, "\xAa\xBb\xCc\xDd\xEe\xFf"},
|
| + // Certain URL-sensitive characters should not be unescaped unless asked.
|
| + {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
|
| + UnescapeRule::SPACES,
|
| + "Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"},
|
| + {"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
|
| + UnescapeRule::URL_SPECIAL_CHARS,
|
| + "Hello%20%13%10world ## ?? == && %% ++"},
|
| + // We can neither escape nor unescape '@' since some websites expect it to
|
| + // be preserved as either '@' or "%40".
|
| + // See http://b/996720 and http://crbug.com/23933 .
|
| + {"me@my%40example", UnescapeRule::NORMAL, "me@my%40example"},
|
| + // Control characters.
|
| + {"%01%02%03%04%05%06%07%08%09 %25",
|
| + UnescapeRule::URL_SPECIAL_CHARS,
|
| + "%01%02%03%04%05%06%07%08%09 %"},
|
| + {"%01%02%03%04%05%06%07%08%09 %25",
|
| + UnescapeRule::CONTROL_CHARS,
|
| + "\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"},
|
| + {"Hello%20%13%10%02", UnescapeRule::SPACES, "Hello %13%10%02"},
|
| + {"Hello%20%13%10%02",
|
| + UnescapeRule::CONTROL_CHARS,
|
| + "Hello%20\x13\x10\x02"},
|
| };
|
|
|
| for (size_t i = 0; i < arraysize(unescape_cases); i++) {
|
| @@ -216,95 +220,120 @@ TEST(EscapeTest, UnescapeURLComponentASCII) {
|
|
|
| TEST(EscapeTest, UnescapeURLComponent) {
|
| const UnescapeURLCase unescape_cases[] = {
|
| - {L"", UnescapeRule::NORMAL, L""},
|
| - {L"%2", UnescapeRule::NORMAL, L"%2"},
|
| - {L"%%%%%%", UnescapeRule::NORMAL, L"%%%%%%"},
|
| - {L"Don't escape anything", UnescapeRule::NORMAL, L"Don't escape anything"},
|
| - {L"Invalid %escape %2", UnescapeRule::NORMAL, L"Invalid %escape %2"},
|
| - {L"Some%20random text %25%2dOK", UnescapeRule::NONE,
|
| - L"Some%20random text %25%2dOK"},
|
| - {L"Some%20random text %25%2dOK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25-OK"},
|
| - {L"Some%20random text %25%E2%80", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25\xE2\x80"},
|
| - {L"Some%20random text %25%E2%80OK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25\xE2\x80OK"},
|
| - {L"Some%20random text %25%E2%80%84OK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25\xE2\x80\x84OK"},
|
| -
|
| - // BiDi Control characters should not be unescaped unless explicity told to
|
| - // do so with UnescapeRule::CONTROL_CHARS
|
| - {L"Some%20random text %25%D8%9COK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25%D8%9COK"},
|
| - {L"Some%20random text %25%E2%80%8EOK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25%E2%80%8EOK"},
|
| - {L"Some%20random text %25%E2%80%8FOK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25%E2%80%8FOK"},
|
| - {L"Some%20random text %25%E2%80%AAOK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25%E2%80%AAOK"},
|
| - {L"Some%20random text %25%E2%80%ABOK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25%E2%80%ABOK"},
|
| - {L"Some%20random text %25%E2%80%AEOK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25%E2%80%AEOK"},
|
| - {L"Some%20random text %25%E2%81%A6OK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25%E2%81%A6OK"},
|
| - {L"Some%20random text %25%E2%81%A9OK", UnescapeRule::NORMAL,
|
| - L"Some%20random text %25%E2%81%A9OK"},
|
| - // UnescapeRule::CONTROL_CHARS should unescape BiDi Control characters.
|
| - {L"Some%20random text %25%D8%9COK",
|
| - UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| - L"Some%20random text %25\xD8\x9COK"},
|
| - {L"Some%20random text %25%E2%80%8EOK",
|
| - UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| - L"Some%20random text %25\xE2\x80\x8EOK"},
|
| - {L"Some%20random text %25%E2%80%8FOK",
|
| - UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| - L"Some%20random text %25\xE2\x80\x8FOK"},
|
| - {L"Some%20random text %25%E2%80%AAOK",
|
| - UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| - L"Some%20random text %25\xE2\x80\xAAOK"},
|
| - {L"Some%20random text %25%E2%80%ABOK",
|
| - UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| - L"Some%20random text %25\xE2\x80\xABOK"},
|
| - {L"Some%20random text %25%E2%80%AEOK",
|
| - UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| - L"Some%20random text %25\xE2\x80\xAEOK"},
|
| - {L"Some%20random text %25%E2%81%A6OK",
|
| - UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| - L"Some%20random text %25\xE2\x81\xA6OK"},
|
| - {L"Some%20random text %25%E2%81%A9OK",
|
| - UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| - L"Some%20random text %25\xE2\x81\xA9OK"},
|
| -
|
| - {L"Some%20random text %25%2dOK", UnescapeRule::SPACES,
|
| - L"Some random text %25-OK"},
|
| - {L"Some%20random text %25%2dOK", UnescapeRule::URL_SPECIAL_CHARS,
|
| - L"Some%20random text %-OK"},
|
| - {L"Some%20random text %25%2dOK",
|
| - UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS,
|
| - L"Some random text %-OK"},
|
| - {L"%A0%B1%C2%D3%E4%F5", UnescapeRule::NORMAL, L"\xA0\xB1\xC2\xD3\xE4\xF5"},
|
| - {L"%Aa%Bb%Cc%Dd%Ee%Ff", UnescapeRule::NORMAL, L"\xAa\xBb\xCc\xDd\xEe\xFf"},
|
| - // Certain URL-sensitive characters should not be unescaped unless asked.
|
| - {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+", UnescapeRule::SPACES,
|
| - L"Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"},
|
| - {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
|
| - UnescapeRule::URL_SPECIAL_CHARS,
|
| - L"Hello%20%13%10world ## ?? == && %% ++"},
|
| - // We can neither escape nor unescape '@' since some websites expect it to
|
| - // be preserved as either '@' or "%40".
|
| - // See http://b/996720 and http://crbug.com/23933 .
|
| - {L"me@my%40example", UnescapeRule::NORMAL, L"me@my%40example"},
|
| - // Control characters.
|
| - {L"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::URL_SPECIAL_CHARS,
|
| - L"%01%02%03%04%05%06%07%08%09 %"},
|
| - {L"%01%02%03%04%05%06%07%08%09 %25", UnescapeRule::CONTROL_CHARS,
|
| - L"\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"},
|
| - {L"Hello%20%13%10%02", UnescapeRule::SPACES, L"Hello %13%10%02"},
|
| - {L"Hello%20%13%10%02", UnescapeRule::CONTROL_CHARS,
|
| - L"Hello%20\x13\x10\x02"},
|
| - {L"Hello\x9824\x9827", UnescapeRule::CONTROL_CHARS,
|
| - L"Hello\x9824\x9827"},
|
| + {L"", UnescapeRule::NORMAL, L""},
|
| + {L"%2", UnescapeRule::NORMAL, L"%2"},
|
| + {L"%%%%%%", UnescapeRule::NORMAL, L"%%%%%%"},
|
| + {L"Don't escape anything",
|
| + UnescapeRule::NORMAL,
|
| + L"Don't escape anything"},
|
| + {L"Invalid %escape %2", UnescapeRule::NORMAL, L"Invalid %escape %2"},
|
| + {L"Some%20random text %25%2dOK",
|
| + UnescapeRule::NONE,
|
| + L"Some%20random text %25%2dOK"},
|
| + {L"Some%20random text %25%2dOK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25-OK"},
|
| + {L"Some%20random text %25%E2%80",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25\xE2\x80"},
|
| + {L"Some%20random text %25%E2%80OK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25\xE2\x80OK"},
|
| + {L"Some%20random text %25%E2%80%84OK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25\xE2\x80\x84OK"},
|
| +
|
| + // BiDi Control characters should not be unescaped unless explicity told
|
| + // to
|
| + // do so with UnescapeRule::CONTROL_CHARS
|
| + {L"Some%20random text %25%D8%9COK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25%D8%9COK"},
|
| + {L"Some%20random text %25%E2%80%8EOK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25%E2%80%8EOK"},
|
| + {L"Some%20random text %25%E2%80%8FOK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25%E2%80%8FOK"},
|
| + {L"Some%20random text %25%E2%80%AAOK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25%E2%80%AAOK"},
|
| + {L"Some%20random text %25%E2%80%ABOK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25%E2%80%ABOK"},
|
| + {L"Some%20random text %25%E2%80%AEOK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25%E2%80%AEOK"},
|
| + {L"Some%20random text %25%E2%81%A6OK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25%E2%81%A6OK"},
|
| + {L"Some%20random text %25%E2%81%A9OK",
|
| + UnescapeRule::NORMAL,
|
| + L"Some%20random text %25%E2%81%A9OK"},
|
| + // UnescapeRule::CONTROL_CHARS should unescape BiDi Control characters.
|
| + {L"Some%20random text %25%D8%9COK",
|
| + UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| + L"Some%20random text %25\xD8\x9COK"},
|
| + {L"Some%20random text %25%E2%80%8EOK",
|
| + UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| + L"Some%20random text %25\xE2\x80\x8EOK"},
|
| + {L"Some%20random text %25%E2%80%8FOK",
|
| + UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| + L"Some%20random text %25\xE2\x80\x8FOK"},
|
| + {L"Some%20random text %25%E2%80%AAOK",
|
| + UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| + L"Some%20random text %25\xE2\x80\xAAOK"},
|
| + {L"Some%20random text %25%E2%80%ABOK",
|
| + UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| + L"Some%20random text %25\xE2\x80\xABOK"},
|
| + {L"Some%20random text %25%E2%80%AEOK",
|
| + UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| + L"Some%20random text %25\xE2\x80\xAEOK"},
|
| + {L"Some%20random text %25%E2%81%A6OK",
|
| + UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| + L"Some%20random text %25\xE2\x81\xA6OK"},
|
| + {L"Some%20random text %25%E2%81%A9OK",
|
| + UnescapeRule::NORMAL | UnescapeRule::CONTROL_CHARS,
|
| + L"Some%20random text %25\xE2\x81\xA9OK"},
|
| +
|
| + {L"Some%20random text %25%2dOK",
|
| + UnescapeRule::SPACES,
|
| + L"Some random text %25-OK"},
|
| + {L"Some%20random text %25%2dOK",
|
| + UnescapeRule::URL_SPECIAL_CHARS,
|
| + L"Some%20random text %-OK"},
|
| + {L"Some%20random text %25%2dOK",
|
| + UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS,
|
| + L"Some random text %-OK"},
|
| + {L"%A0%B1%C2%D3%E4%F5",
|
| + UnescapeRule::NORMAL,
|
| + L"\xA0\xB1\xC2\xD3\xE4\xF5"},
|
| + {L"%Aa%Bb%Cc%Dd%Ee%Ff",
|
| + UnescapeRule::NORMAL,
|
| + L"\xAa\xBb\xCc\xDd\xEe\xFf"},
|
| + // Certain URL-sensitive characters should not be unescaped unless asked.
|
| + {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
|
| + UnescapeRule::SPACES,
|
| + L"Hello %13%10world %23# %3F? %3D= %26& %25% %2B+"},
|
| + {L"Hello%20%13%10world %23# %3F? %3D= %26& %25% %2B+",
|
| + UnescapeRule::URL_SPECIAL_CHARS,
|
| + L"Hello%20%13%10world ## ?? == && %% ++"},
|
| + // We can neither escape nor unescape '@' since some websites expect it to
|
| + // be preserved as either '@' or "%40".
|
| + // See http://b/996720 and http://crbug.com/23933 .
|
| + {L"me@my%40example", UnescapeRule::NORMAL, L"me@my%40example"},
|
| + // Control characters.
|
| + {L"%01%02%03%04%05%06%07%08%09 %25",
|
| + UnescapeRule::URL_SPECIAL_CHARS,
|
| + L"%01%02%03%04%05%06%07%08%09 %"},
|
| + {L"%01%02%03%04%05%06%07%08%09 %25",
|
| + UnescapeRule::CONTROL_CHARS,
|
| + L"\x01\x02\x03\x04\x05\x06\x07\x08\x09 %25"},
|
| + {L"Hello%20%13%10%02", UnescapeRule::SPACES, L"Hello %13%10%02"},
|
| + {L"Hello%20%13%10%02",
|
| + UnescapeRule::CONTROL_CHARS,
|
| + L"Hello%20\x13\x10\x02"},
|
| + {L"Hello\x9824\x9827", UnescapeRule::CONTROL_CHARS, L"Hello\x9824\x9827"},
|
| };
|
|
|
| for (size_t i = 0; i < arraysize(unescape_cases); i++) {
|
| @@ -335,51 +364,39 @@ TEST(EscapeTest, UnescapeURLComponent) {
|
|
|
| TEST(EscapeTest, UnescapeAndDecodeUTF8URLComponent) {
|
| const UnescapeAndDecodeCase unescape_cases[] = {
|
| - { "%",
|
| - "%",
|
| - "%",
|
| - L"%"},
|
| - { "+",
|
| - "+",
|
| - " ",
|
| - L"+"},
|
| - { "%2+",
|
| - "%2+",
|
| - "%2 ",
|
| - L"%2+"},
|
| - { "+%%%+%%%",
|
| - "+%%%+%%%",
|
| - " %%% %%%",
|
| - L"+%%%+%%%"},
|
| - { "Don't escape anything",
|
| - "Don't escape anything",
|
| - "Don't escape anything",
|
| - L"Don't escape anything"},
|
| - { "+Invalid %escape %2+",
|
| - "+Invalid %escape %2+",
|
| - " Invalid %escape %2 ",
|
| - L"+Invalid %escape %2+"},
|
| - { "Some random text %25%2dOK",
|
| - "Some random text %25-OK",
|
| - "Some random text %25-OK",
|
| - L"Some random text %25-OK"},
|
| - { "%01%02%03%04%05%06%07%08%09",
|
| - "%01%02%03%04%05%06%07%08%09",
|
| - "%01%02%03%04%05%06%07%08%09",
|
| - L"%01%02%03%04%05%06%07%08%09"},
|
| - { "%E4%BD%A0+%E5%A5%BD",
|
| - "\xE4\xBD\xA0+\xE5\xA5\xBD",
|
| - "\xE4\xBD\xA0 \xE5\xA5\xBD",
|
| - L"\x4f60+\x597d"},
|
| - { "%ED%ED", // Invalid UTF-8.
|
| - "\xED\xED",
|
| - "\xED\xED",
|
| - L"%ED%ED"}, // Invalid UTF-8 -> kept unescaped.
|
| + {"%", "%", "%", L"%"},
|
| + {"+", "+", " ", L"+"},
|
| + {"%2+", "%2+", "%2 ", L"%2+"},
|
| + {"+%%%+%%%", "+%%%+%%%", " %%% %%%", L"+%%%+%%%"},
|
| + {"Don't escape anything",
|
| + "Don't escape anything",
|
| + "Don't escape anything",
|
| + L"Don't escape anything"},
|
| + {"+Invalid %escape %2+",
|
| + "+Invalid %escape %2+",
|
| + " Invalid %escape %2 ",
|
| + L"+Invalid %escape %2+"},
|
| + {"Some random text %25%2dOK",
|
| + "Some random text %25-OK",
|
| + "Some random text %25-OK",
|
| + L"Some random text %25-OK"},
|
| + {"%01%02%03%04%05%06%07%08%09",
|
| + "%01%02%03%04%05%06%07%08%09",
|
| + "%01%02%03%04%05%06%07%08%09",
|
| + L"%01%02%03%04%05%06%07%08%09"},
|
| + {"%E4%BD%A0+%E5%A5%BD",
|
| + "\xE4\xBD\xA0+\xE5\xA5\xBD",
|
| + "\xE4\xBD\xA0 \xE5\xA5\xBD",
|
| + L"\x4f60+\x597d"},
|
| + {"%ED%ED", // Invalid UTF-8.
|
| + "\xED\xED",
|
| + "\xED\xED",
|
| + L"%ED%ED"}, // Invalid UTF-8 -> kept unescaped.
|
| };
|
|
|
| for (size_t i = 0; i < arraysize(unescape_cases); i++) {
|
| - std::string unescaped = UnescapeURLComponent(unescape_cases[i].input,
|
| - UnescapeRule::NORMAL);
|
| + std::string unescaped =
|
| + UnescapeURLComponent(unescape_cases[i].input, UnescapeRule::NORMAL);
|
| EXPECT_EQ(std::string(unescape_cases[i].url_unescaped), unescaped);
|
|
|
| unescaped = UnescapeURLComponent(unescape_cases[i].input,
|
| @@ -395,44 +412,44 @@ TEST(EscapeTest, UnescapeAndDecodeUTF8URLComponent) {
|
|
|
| TEST(EscapeTest, AdjustOffset) {
|
| const AdjustOffsetCase adjust_cases[] = {
|
| - {"", 0, 0},
|
| - {"test", 0, 0},
|
| - {"test", 2, 2},
|
| - {"test", 4, 4},
|
| - {"test", std::string::npos, std::string::npos},
|
| - {"%2dtest", 6, 4},
|
| - {"%2dtest", 3, 1},
|
| - {"%2dtest", 2, std::string::npos},
|
| - {"%2dtest", 1, std::string::npos},
|
| - {"%2dtest", 0, 0},
|
| - {"test%2d", 2, 2},
|
| - {"%E4%BD%A0+%E5%A5%BD", 9, 1},
|
| - {"%E4%BD%A0+%E5%A5%BD", 6, std::string::npos},
|
| - {"%E4%BD%A0+%E5%A5%BD", 0, 0},
|
| - {"%E4%BD%A0+%E5%A5%BD", 10, 2},
|
| - {"%E4%BD%A0+%E5%A5%BD", 19, 3},
|
| -
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 18, 8},
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 15, std::string::npos},
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 9, 7},
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 19, 9},
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 28, 10},
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 0, 0},
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 2, 2},
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 3, std::string::npos},
|
| - {"hi%41test%E4%BD%A0+%E5%A5%BD", 5, 3},
|
| -
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 9, 1},
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 6, std::string::npos},
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 0, 0},
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 10, 2},
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 19, 3},
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 21, 5},
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 22, std::string::npos},
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 24, 6},
|
| - {"%E4%BD%A0+%E5%A5%BDhi%41test", 28, 10},
|
| -
|
| - {"%ED%B0%80+%E5%A5%BD", 6, 6}, // not convertable to UTF-8
|
| + {"", 0, 0},
|
| + {"test", 0, 0},
|
| + {"test", 2, 2},
|
| + {"test", 4, 4},
|
| + {"test", std::string::npos, std::string::npos},
|
| + {"%2dtest", 6, 4},
|
| + {"%2dtest", 3, 1},
|
| + {"%2dtest", 2, std::string::npos},
|
| + {"%2dtest", 1, std::string::npos},
|
| + {"%2dtest", 0, 0},
|
| + {"test%2d", 2, 2},
|
| + {"%E4%BD%A0+%E5%A5%BD", 9, 1},
|
| + {"%E4%BD%A0+%E5%A5%BD", 6, std::string::npos},
|
| + {"%E4%BD%A0+%E5%A5%BD", 0, 0},
|
| + {"%E4%BD%A0+%E5%A5%BD", 10, 2},
|
| + {"%E4%BD%A0+%E5%A5%BD", 19, 3},
|
| +
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 18, 8},
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 15, std::string::npos},
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 9, 7},
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 19, 9},
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 28, 10},
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 0, 0},
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 2, 2},
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 3, std::string::npos},
|
| + {"hi%41test%E4%BD%A0+%E5%A5%BD", 5, 3},
|
| +
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 9, 1},
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 6, std::string::npos},
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 0, 0},
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 10, 2},
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 19, 3},
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 21, 5},
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 22, std::string::npos},
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 24, 6},
|
| + {"%E4%BD%A0+%E5%A5%BDhi%41test", 28, 10},
|
| +
|
| + {"%ED%B0%80+%E5%A5%BD", 6, 6}, // not convertable to UTF-8
|
| };
|
|
|
| for (size_t i = 0; i < arraysize(adjust_cases); i++) {
|
| @@ -449,9 +466,9 @@ TEST(EscapeTest, AdjustOffset) {
|
|
|
| TEST(EscapeTest, EscapeForHTML) {
|
| const EscapeForHTMLCase tests[] = {
|
| - { "hello", "hello" },
|
| - { "<hello>", "<hello>" },
|
| - { "don\'t mess with me", "don't mess with me" },
|
| + {"hello", "hello"},
|
| + {"<hello>", "<hello>"},
|
| + {"don\'t mess with me", "don't mess with me"},
|
| };
|
| for (size_t i = 0; i < arraysize(tests); ++i) {
|
| std::string result = EscapeForHTML(std::string(tests[i].input));
|
| @@ -461,17 +478,17 @@ TEST(EscapeTest, EscapeForHTML) {
|
|
|
| TEST(EscapeTest, UnescapeForHTML) {
|
| const EscapeForHTMLCase tests[] = {
|
| - { "", "" },
|
| - { "<hello>", "<hello>" },
|
| - { "don't mess with me", "don\'t mess with me" },
|
| - { "<>&"'", "<>&\"'" },
|
| - { "& lt; & ; &; '", "& lt; & ; &; '" },
|
| - { "&", "&" },
|
| - { """, "\"" },
|
| - { "'", "'" },
|
| - { "<", "<" },
|
| - { ">", ">" },
|
| - { "& &", "& &" },
|
| + {"", ""},
|
| + {"<hello>", "<hello>"},
|
| + {"don't mess with me", "don\'t mess with me"},
|
| + {"<>&"'", "<>&\"'"},
|
| + {"& lt; & ; &; '", "& lt; & ; &; '"},
|
| + {"&", "&"},
|
| + {""", "\""},
|
| + {"'", "'"},
|
| + {"<", "<"},
|
| + {">", ">"},
|
| + {"& &", "& &"},
|
| };
|
| for (size_t i = 0; i < arraysize(tests); ++i) {
|
| base::string16 result = UnescapeForHTML(base::ASCIIToUTF16(tests[i].input));
|
|
|