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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 "%7B%7C%7D~%7F%80%FF"); | 140 "%7B%7C%7D~%7F%80%FF"); |
141 } | 141 } |
142 | 142 |
143 TEST(EscapeTest, EscapeUrlEncodedData) { | 143 TEST(EscapeTest, EscapeUrlEncodedData) { |
144 ASSERT_EQ( | 144 ASSERT_EQ( |
145 // Most of the character space we care about, un-escaped | 145 // Most of the character space we care about, un-escaped |
146 EscapeUrlEncodedData( | 146 EscapeUrlEncodedData( |
147 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" | 147 "\x02\n\x1d !\"#$%&'()*+,-./0123456789:;" |
148 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 148 "<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
149 "[\\]^_`abcdefghijklmnopqrstuvwxyz" | 149 "[\\]^_`abcdefghijklmnopqrstuvwxyz" |
150 "{|}~\x7f\x80\xff"), | 150 "{|}~\x7f\x80\xff", true), |
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(EscapeUrlEncodedData("a b", true), "a+b"); |
| 160 ASSERT_EQ(EscapeUrlEncodedData("a b", false), "a%20b"); |
| 161 } |
| 162 |
158 TEST(EscapeTest, UnescapeURLComponentASCII) { | 163 TEST(EscapeTest, UnescapeURLComponentASCII) { |
159 const UnescapeURLCaseASCII unescape_cases[] = { | 164 const UnescapeURLCaseASCII unescape_cases[] = { |
160 {"", UnescapeRule::NORMAL, ""}, | 165 {"", UnescapeRule::NORMAL, ""}, |
161 {"%2", UnescapeRule::NORMAL, "%2"}, | 166 {"%2", UnescapeRule::NORMAL, "%2"}, |
162 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, | 167 {"%%%%%%", UnescapeRule::NORMAL, "%%%%%%"}, |
163 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, | 168 {"Don't escape anything", UnescapeRule::NORMAL, "Don't escape anything"}, |
164 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, | 169 {"Invalid %escape %2", UnescapeRule::NORMAL, "Invalid %escape %2"}, |
165 {"Some%20random text %25%2dOK", UnescapeRule::NONE, | 170 {"Some%20random text %25%2dOK", UnescapeRule::NONE, |
166 "Some%20random text %25%2dOK"}, | 171 "Some%20random text %25%2dOK"}, |
167 {"Some%20random text %25%2dOK", UnescapeRule::NORMAL, | 172 {"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); | 436 adjustments.push_back(9); |
432 adjustments.push_back(15); | 437 adjustments.push_back(15); |
433 std::for_each(offsets.begin(), offsets.end(), | 438 std::for_each(offsets.begin(), offsets.end(), |
434 AdjustEncodingOffset(adjustments)); | 439 AdjustEncodingOffset(adjustments)); |
435 size_t expected_2[] = {0, kNpos, kNpos, 1, 2, 3, 4, kNpos, kNpos, 5, kNpos, | 440 size_t expected_2[] = {0, kNpos, kNpos, 1, 2, 3, 4, kNpos, kNpos, 5, kNpos, |
436 kNpos, 6, 7, 8, 9, kNpos, kNpos}; | 441 kNpos, 6, 7, 8, 9, kNpos, kNpos}; |
437 EXPECT_EQ(offsets.size(), arraysize(expected_2)); | 442 EXPECT_EQ(offsets.size(), arraysize(expected_2)); |
438 for (size_t i = 0; i < arraysize(expected_2); ++i) | 443 for (size_t i = 0; i < arraysize(expected_2); ++i) |
439 EXPECT_EQ(expected_2[i], offsets[i]); | 444 EXPECT_EQ(expected_2[i], offsets[i]); |
440 } | 445 } |
OLD | NEW |