| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "net/base/escape.h" | 7 #include "net/base/escape.h" |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 100 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 101 "[\\]^_`abcdefghijklmnopqrstuvwxyz" | 101 "[\\]^_`abcdefghijklmnopqrstuvwxyz" |
| 102 "{|}~\x7f\x80\xff"), | 102 "{|}~\x7f\x80\xff"), |
| 103 // Escaped | 103 // Escaped |
| 104 "%02%0A%1D%20!%22%23$%25&'()*+,-./0123456789%3A;" | 104 "%02%0A%1D%20!%22%23$%25&'()*+,-./0123456789%3A;" |
| 105 "%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 105 "%3C=%3E%3F@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 106 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" | 106 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" |
| 107 "%7B%7C%7D~%7F%80%FF"); | 107 "%7B%7C%7D~%7F%80%FF"); |
| 108 } | 108 } |
| 109 | 109 |
| 110 TEST(Escape, EscapeUrl) { |
| 111 ASSERT_EQ( |
| 112 // Most of the character space we care about, un-escaped |
| 113 EscapeUrl( |
| 114 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" |
| 115 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 116 "[\\]^_`abcdefghijklmnopqrstuvwxyz" |
| 117 "{|}~\x7f\x80\xff"), |
| 118 // Escaped |
| 119 "%02%0A%1D+!%22%23%24%25%26%27()*%2B,-./0123456789:%3B" |
| 120 "%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 121 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" |
| 122 "%7B%7C%7D~%7F%80%FF"); |
| 123 } |
| 124 |
| 110 TEST(Escape, UnescapeURLComponent) { | 125 TEST(Escape, UnescapeURLComponent) { |
| 111 const UnescapeURLCase unescape_cases[] = { | 126 const UnescapeURLCase unescape_cases[] = { |
| 112 {"", UnescapeRule::NORMAL, ""}, | 127 {"", UnescapeRule::NORMAL, ""}, |
| 113 {"%2", UnescapeRule::NORMAL, "%2"}, | 128 {"%2", UnescapeRule::NORMAL, "%2"}, |
| 114 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, | 129 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, |
| 115 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, | 130 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, |
| 116 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, | 131 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, |
| 117 {"Some%20random text %25%3bOK", UnescapeRule::NONE, | 132 {"Some%20random text %25%3bOK", UnescapeRule::NONE, |
| 118 "Some%20random text %25%3bOK"}, | 133 "Some%20random text %25%3bOK"}, |
| 119 {"Some%20random text %25%3bOK", UnescapeRule::NORMAL, | 134 {"Some%20random text %25%3bOK", UnescapeRule::NORMAL, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 const EscapeForHTMLCase tests[] = { | 240 const EscapeForHTMLCase tests[] = { |
| 226 { "hello", "hello" }, | 241 { "hello", "hello" }, |
| 227 { "<hello>", "<hello>" }, | 242 { "<hello>", "<hello>" }, |
| 228 { "don\'t mess with me", "don't mess with me" }, | 243 { "don\'t mess with me", "don't mess with me" }, |
| 229 }; | 244 }; |
| 230 for (size_t i = 0; i < arraysize(tests); ++i) { | 245 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 231 std::string result = EscapeForHTML(std::string(tests[i].input)); | 246 std::string result = EscapeForHTML(std::string(tests[i].input)); |
| 232 EXPECT_EQ(std::string(tests[i].expected_output), result); | 247 EXPECT_EQ(std::string(tests[i].expected_output), result); |
| 233 } | 248 } |
| 234 } | 249 } |
| OLD | NEW |