OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "net/base/escape.h" | 8 #include "net/base/escape.h" |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 148 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
149 "[\\]^_`abcdefghijklmnopqrstuvwxyz" | 149 "[\\]^_`abcdefghijklmnopqrstuvwxyz" |
150 "{|}~\x7f\x80\xff"), | 150 "{|}~\x7f\x80\xff"), |
151 // Escaped | 151 // Escaped |
152 "%02%0A%1D+!%22%23%24%25%26%27()*%2B,-./0123456789:%3B" | 152 "%02%0A%1D+!%22%23%24%25%26%27()*%2B,-./0123456789:%3B" |
153 "%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 153 "%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
154 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" | 154 "%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz" |
155 "%7B%7C%7D~%7F%80%FF"); | 155 "%7B%7C%7D~%7F%80%FF"); |
156 } | 156 } |
157 | 157 |
| 158 TEST(EscapeTest, EscapeUrlEncodedDataSpace) { |
| 159 ASSERT_EQ( |
| 160 EscapeUrlEncodedData( |
| 161 "a b"), |
| 162 // Escaped |
| 163 "a+b"); |
| 164 ASSERT_EQ( |
| 165 EscapeUrlEncodedData( |
| 166 "a b", false), |
| 167 // Escaped |
| 168 "a%20b"); |
| 169 } |
| 170 |
158 TEST(EscapeTest, UnescapeURLComponentASCII) { | 171 TEST(EscapeTest, UnescapeURLComponentASCII) { |
159 const UnescapeURLCaseASCII unescape_cases[] = { | 172 const UnescapeURLCaseASCII unescape_cases[] = { |
160 {"", UnescapeRule::NORMAL, ""}, | 173 {"", UnescapeRule::NORMAL, ""}, |
161 {"%2", UnescapeRule::NORMAL, "%2"}, | 174 {"%2", UnescapeRule::NORMAL, "%2"}, |
162 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, | 175 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, |
163 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, | 176 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, |
164 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, | 177 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, |
165 {"Some%20random text %25%2dOK", UnescapeRule::NONE, | 178 {"Some%20random text %25%2dOK", UnescapeRule::NONE, |
166 "Some%20random text %25%2dOK"}, | 179 "Some%20random text %25%2dOK"}, |
167 {"Some%20random text %25%2dOK", UnescapeRule::NORMAL, | 180 {"Some%20random text %25%2dOK", UnescapeRule::NORMAL, |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 adjustments.push_back(9); | 444 adjustments.push_back(9); |
432 adjustments.push_back(15); | 445 adjustments.push_back(15); |
433 std::for_each(offsets.begin(), offsets.end(), | 446 std::for_each(offsets.begin(), offsets.end(), |
434 AdjustEncodingOffset(adjustments)); | 447 AdjustEncodingOffset(adjustments)); |
435 size_t expected_2[] = {0, kNpos, kNpos, 1, 2, 3, 4, kNpos, kNpos, 5, kNpos, | 448 size_t expected_2[] = {0, kNpos, kNpos, 1, 2, 3, 4, kNpos, kNpos, 5, kNpos, |
436 kNpos, 6, 7, 8, 9, kNpos, kNpos}; | 449 kNpos, 6, 7, 8, 9, kNpos, kNpos}; |
437 EXPECT_EQ(offsets.size(), arraysize(expected_2)); | 450 EXPECT_EQ(offsets.size(), arraysize(expected_2)); |
438 for (size_t i = 0; i < arraysize(expected_2); ++i) | 451 for (size_t i = 0; i < arraysize(expected_2); ++i) |
439 EXPECT_EQ(expected_2[i], offsets[i]); | 452 EXPECT_EQ(expected_2[i], offsets[i]); |
440 } | 453 } |
OLD | NEW |