| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <errno.h> | 5 #include <errno.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/third_party/mozilla/url_parse.h" | 9 #include "url/third_party/mozilla/url_parse.h" |
| 10 #include "url/url_canon.h" | 10 #include "url/url_canon.h" |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 // Backslashes should get converted to forward slashes | 1053 // Backslashes should get converted to forward slashes |
| 1054 {"\\foo\\bar", L"\\foo\\bar", "/foo/bar", Component(0, 8), true}, | 1054 {"\\foo\\bar", L"\\foo\\bar", "/foo/bar", Component(0, 8), true}, |
| 1055 // Hashes found in paths (possibly only when the caller explicitly sets | 1055 // Hashes found in paths (possibly only when the caller explicitly sets |
| 1056 // the path on an already-parsed URL) should be escaped. | 1056 // the path on an already-parsed URL) should be escaped. |
| 1057 {"/foo#bar", L"/foo#bar", "/foo%23bar", Component(0, 10), true}, | 1057 {"/foo#bar", L"/foo#bar", "/foo%23bar", Component(0, 10), true}, |
| 1058 // %7f should be allowed and %3D should not be unescaped (these were wrong | 1058 // %7f should be allowed and %3D should not be unescaped (these were wrong |
| 1059 // in a previous version). | 1059 // in a previous version). |
| 1060 {"/%7Ffp3%3Eju%3Dduvgw%3Dd", L"/%7Ffp3%3Eju%3Dduvgw%3Dd", "/%7Ffp3%3Eju%3Ddu
vgw%3Dd", Component(0, 24), true}, | 1060 {"/%7Ffp3%3Eju%3Dduvgw%3Dd", L"/%7Ffp3%3Eju%3Dduvgw%3Dd", "/%7Ffp3%3Eju%3Ddu
vgw%3Dd", Component(0, 24), true}, |
| 1061 // @ should be passed through unchanged (escaped or unescaped). | 1061 // @ should be passed through unchanged (escaped or unescaped). |
| 1062 {"/@asdf%40", L"/@asdf%40", "/@asdf%40", Component(0, 9), true}, | 1062 {"/@asdf%40", L"/@asdf%40", "/@asdf%40", Component(0, 9), true}, |
| 1063 // Nested escape sequences should result in escaping the leading '%' if |
| 1064 // unescaping would result in a new escape sequence. |
| 1065 {"/%A%42", L"/%A%42", "/%25AB", Component(0, 6), true}, |
| 1066 {"/%%41B", L"/%%41B", "/%25AB", Component(0, 6), true}, |
| 1067 {"/%%41%42", L"/%%41%42", "/%25AB", Component(0, 6), true}, |
| 1068 // Make sure truncated "nested" escapes don't result in reading off the |
| 1069 // string end. |
| 1070 {"/%%41", L"/%%41", "/%A", Component(0, 3), true}, |
| 1071 // Don't unescape the leading '%' if unescaping doesn't result in a valid |
| 1072 // new escape sequence. |
| 1073 {"/%%470", L"/%%470", "/%G0", Component(0, 4), true}, |
| 1074 {"/%%2D%41", L"/%%2D%41", "/%-A", Component(0, 4), true}, |
| 1075 // Don't erroneously downcast a UTF-16 charater in a way that makes it |
| 1076 // look like part of an escape sequence. |
| 1077 {NULL, L"/%%41\x0130", "/%A%C4%B0", Component(0, 9), true}, |
| 1063 | 1078 |
| 1064 // ----- encoding tests ----- | 1079 // ----- encoding tests ----- |
| 1065 // Basic conversions | 1080 // Basic conversions |
| 1066 {"/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", L"/\x4f60\x597d\x4f60\
x597d", "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD", Component(0, 37), true}, | 1081 {"/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", L"/\x4f60\x597d\x4f60\
x597d", "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD", Component(0, 37), true}, |
| 1067 // Invalid unicode characters should fail. We only do validation on | 1082 // Invalid unicode characters should fail. We only do validation on |
| 1068 // UTF-16 input, so this doesn't happen on 8-bit. | 1083 // UTF-16 input, so this doesn't happen on 8-bit. |
| 1069 {"/\xef\xb7\x90zyx", NULL, "/%EF%B7%90zyx", Component(0, 13), true}, | 1084 {"/\xef\xb7\x90zyx", NULL, "/%EF%B7%90zyx", Component(0, 13), true}, |
| 1070 {NULL, L"/\xfdd0zyx", "/%EF%BF%BDzyx", Component(0, 13), false}, | 1085 {NULL, L"/\xfdd0zyx", "/%EF%BF%BDzyx", Component(0, 13), false}, |
| 1071 }; | 1086 }; |
| 1072 | 1087 |
| (...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2123 repl_output.Complete(); | 2138 repl_output.Complete(); |
| 2124 | 2139 |
| 2125 // Generate the expected string and check. | 2140 // Generate the expected string and check. |
| 2126 std::string expected("file:///foo?"); | 2141 std::string expected("file:///foo?"); |
| 2127 for (size_t i = 0; i < new_query.length(); i++) | 2142 for (size_t i = 0; i < new_query.length(); i++) |
| 2128 expected.push_back('a'); | 2143 expected.push_back('a'); |
| 2129 EXPECT_TRUE(expected == repl_str); | 2144 EXPECT_TRUE(expected == repl_str); |
| 2130 } | 2145 } |
| 2131 | 2146 |
| 2132 } // namespace url | 2147 } // namespace url |
| OLD | NEW |