| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/tools/flip_server/url_utilities.h" | 5 #include "net/tools/flip_server/url_utilities.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 EXPECT_EQ("http://www.foo.com", UrlUtilities::Unescape("http://www.foo.com")); | 54 EXPECT_EQ("http://www.foo.com", UrlUtilities::Unescape("http://www.foo.com")); |
| 55 EXPECT_EQ("www.foo.com:80/news?q=hello", | 55 EXPECT_EQ("www.foo.com:80/news?q=hello", |
| 56 UrlUtilities::Unescape("www.foo.com:80/news?q=hello")); | 56 UrlUtilities::Unescape("www.foo.com:80/news?q=hello")); |
| 57 | 57 |
| 58 // All chars can be unescaped. | 58 // All chars can be unescaped. |
| 59 EXPECT_EQ("~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", | 59 EXPECT_EQ("~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", |
| 60 UrlUtilities::Unescape("%7E%60%21%40%23%24%25%5E%26%2A%28%29%5F%2D" | 60 UrlUtilities::Unescape("%7E%60%21%40%23%24%25%5E%26%2A%28%29%5F%2D" |
| 61 "%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22%27%3C%2C" | 61 "%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22%27%3C%2C" |
| 62 "%3E%2E%3F%2F")); | 62 "%3E%2E%3F%2F")); |
| 63 for (int c = 0; c < 256; ++c) { | 63 for (int c = 0; c < 256; ++c) { |
| 64 std::string unescaped_char(1, implicit_cast<unsigned char>(c)); | 64 std::string unescaped_char(1, static_cast<unsigned char>(c)); |
| 65 std::string escaped_char = base::StringPrintf("%%%02X", c); | 65 std::string escaped_char = base::StringPrintf("%%%02X", c); |
| 66 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char)) | 66 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char)) |
| 67 << "escaped_char = " << escaped_char; | 67 << "escaped_char = " << escaped_char; |
| 68 escaped_char = base::StringPrintf("%%%02x", c); | 68 escaped_char = base::StringPrintf("%%%02x", c); |
| 69 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char)) | 69 EXPECT_EQ(unescaped_char, UrlUtilities::Unescape(escaped_char)) |
| 70 << "escaped_char = " << escaped_char; | 70 << "escaped_char = " << escaped_char; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // All non-% chars are left alone. | 73 // All non-% chars are left alone. |
| 74 EXPECT_EQ("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/", | 74 EXPECT_EQ("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/", |
| 75 UrlUtilities::Unescape("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/")); | 75 UrlUtilities::Unescape("~`!@#$^&*()_-+={[}]|\\:;\"'<,>.?/")); |
| 76 for (int c = 0; c < 256; ++c) { | 76 for (int c = 0; c < 256; ++c) { |
| 77 if (c != '%') { | 77 if (c != '%') { |
| 78 std::string just_char(1, implicit_cast<unsigned char>(c)); | 78 std::string just_char(1, static_cast<unsigned char>(c)); |
| 79 EXPECT_EQ(just_char, UrlUtilities::Unescape(just_char)); | 79 EXPECT_EQ(just_char, UrlUtilities::Unescape(just_char)); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Some examples to unescape. | 83 // Some examples to unescape. |
| 84 EXPECT_EQ("Hello, world!", UrlUtilities::Unescape("Hello%2C world%21")); | 84 EXPECT_EQ("Hello, world!", UrlUtilities::Unescape("Hello%2C world%21")); |
| 85 | 85 |
| 86 // Not actually escapes. | 86 // Not actually escapes. |
| 87 EXPECT_EQ("%", UrlUtilities::Unescape("%")); | 87 EXPECT_EQ("%", UrlUtilities::Unescape("%")); |
| 88 EXPECT_EQ("%www", UrlUtilities::Unescape("%www")); | 88 EXPECT_EQ("%www", UrlUtilities::Unescape("%www")); |
| 89 EXPECT_EQ("%foo", UrlUtilities::Unescape("%foo")); | 89 EXPECT_EQ("%foo", UrlUtilities::Unescape("%foo")); |
| 90 EXPECT_EQ("%1", UrlUtilities::Unescape("%1")); | 90 EXPECT_EQ("%1", UrlUtilities::Unescape("%1")); |
| 91 EXPECT_EQ("%1x", UrlUtilities::Unescape("%1x")); | 91 EXPECT_EQ("%1x", UrlUtilities::Unescape("%1x")); |
| 92 EXPECT_EQ("%%", UrlUtilities::Unescape("%%")); | 92 EXPECT_EQ("%%", UrlUtilities::Unescape("%%")); |
| 93 // Escapes following non-escapes. | 93 // Escapes following non-escapes. |
| 94 EXPECT_EQ("%!", UrlUtilities::Unescape("%%21")); | 94 EXPECT_EQ("%!", UrlUtilities::Unescape("%%21")); |
| 95 EXPECT_EQ("%2!", UrlUtilities::Unescape("%2%21")); | 95 EXPECT_EQ("%2!", UrlUtilities::Unescape("%2%21")); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace net | 98 } // namespace net |
| OLD | NEW |