Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: url/url_canon_unittest.cc

Issue 2378213002: Mark URLs with empty schemes as invalid. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« url/url_canon_etc.cc ('K') | « url/url_canon_etc.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <stddef.h> 6 #include <stddef.h>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/third_party/mozilla/url_parse.h" 10 #include "url/third_party/mozilla/url_parse.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 EXPECT_EQ(scheme_cases[i].expected_component.begin, out_comp.begin); 275 EXPECT_EQ(scheme_cases[i].expected_component.begin, out_comp.begin);
276 EXPECT_EQ(scheme_cases[i].expected_component.len, out_comp.len); 276 EXPECT_EQ(scheme_cases[i].expected_component.len, out_comp.len);
277 } 277 }
278 278
279 // Test the case where the scheme is declared nonexistent, it should be 279 // Test the case where the scheme is declared nonexistent, it should be
280 // converted into an empty scheme. 280 // converted into an empty scheme.
281 Component out_comp; 281 Component out_comp;
282 out_str.clear(); 282 out_str.clear();
283 StdStringCanonOutput output(&out_str); 283 StdStringCanonOutput output(&out_str);
284 284
285 EXPECT_TRUE(CanonicalizeScheme("", Component(0, -1), &output, &out_comp)); 285 EXPECT_FALSE(CanonicalizeScheme("", Component(0, -1), &output, &out_comp));
286 output.Complete(); 286 output.Complete();
287 287
288 EXPECT_EQ(std::string(":"), out_str); 288 EXPECT_EQ(std::string(":"), out_str);
289 EXPECT_EQ(0, out_comp.begin); 289 EXPECT_EQ(0, out_comp.begin);
290 EXPECT_EQ(0, out_comp.len); 290 EXPECT_EQ(0, out_comp.len);
291 } 291 }
292 292
293 TEST(URLCanonTest, Host) { 293 TEST(URLCanonTest, Host) {
294 IPAddressCase host_cases[] = { 294 IPAddressCase host_cases[] = {
295 // Basic canonicalization, uppercase should be converted to lowercase. 295 // Basic canonicalization, uppercase should be converted to lowercase.
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 // parts are included or excluded properly, and have the correct separators. 1296 // parts are included or excluded properly, and have the correct separators.
1297 struct URLCase { 1297 struct URLCase {
1298 const char* input; 1298 const char* input;
1299 const char* expected; 1299 const char* expected;
1300 bool expected_success; 1300 bool expected_success;
1301 } cases[] = { 1301 } cases[] = {
1302 {"http://www.google.com/foo?bar=baz#", "http://www.google.com/foo?bar=baz#", true}, 1302 {"http://www.google.com/foo?bar=baz#", "http://www.google.com/foo?bar=baz#", true},
1303 {"http://[www.google.com]/", "http://[www.google.com]/", false}, 1303 {"http://[www.google.com]/", "http://[www.google.com]/", false},
1304 {"ht\ttp:@www.google.com:80/;p?#", "ht%09tp://www.google.com:80/;p?#", false }, 1304 {"ht\ttp:@www.google.com:80/;p?#", "ht%09tp://www.google.com:80/;p?#", false },
1305 {"http:////////user:@google.com:99?foo", "http://user@google.com:99/?foo", t rue}, 1305 {"http:////////user:@google.com:99?foo", "http://user@google.com:99/?foo", t rue},
1306 {"www.google.com", ":www.google.com/", true}, 1306 {"www.google.com", ":www.google.com/", false},
1307 {"http://192.0x00A80001", "http://192.168.0.1/", true}, 1307 {"http://192.0x00A80001", "http://192.168.0.1/", true},
1308 {"http://www/foo%2Ehtml", "http://www/foo.html", true}, 1308 {"http://www/foo%2Ehtml", "http://www/foo.html", true},
1309 {"http://user:pass@/", "http://user:pass@/", false}, 1309 {"http://user:pass@/", "http://user:pass@/", false},
1310 {"http://%25DOMAIN:foobar@foodomain.com/", "http://%25DOMAIN:foobar@foodomai n.com/", true}, 1310 {"http://%25DOMAIN:foobar@foodomain.com/", "http://%25DOMAIN:foobar@foodomai n.com/", true},
1311 1311
1312 // Backslashes should get converted to forward slashes. 1312 // Backslashes should get converted to forward slashes.
1313 {"http:\\\\www.google.com\\foo", "http://www.google.com/foo", true}, 1313 {"http:\\\\www.google.com\\foo", "http://www.google.com/foo", true},
1314 1314
1315 // Busted refs shouldn't make the whole thing fail. 1315 // Busted refs shouldn't make the whole thing fail.
1316 {"http://www.google.com/asdf#\xc2", "http://www.google.com/asdf#\xef\xbf\xbd ", true}, 1316 {"http://www.google.com/asdf#\xc2", "http://www.google.com/asdf#\xef\xbf\xbd ", true},
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 EXPECT_EQ(10, out_parsed.scheme.len); 1747 EXPECT_EQ(10, out_parsed.scheme.len);
1748 if (success) 1748 if (success)
1749 EXPECT_GT(out_parsed.path.len, 0); 1749 EXPECT_GT(out_parsed.path.len, 0);
1750 } 1750 }
1751 } 1751 }
1752 1752
1753 TEST(URLCanonTest, CanonicalizePathURL) { 1753 TEST(URLCanonTest, CanonicalizePathURL) {
1754 // Path URLs should get canonicalized schemes but nothing else. 1754 // Path URLs should get canonicalized schemes but nothing else.
1755 struct PathCase { 1755 struct PathCase {
1756 const char* input; 1756 const char* input;
1757 bool expected_success;
1757 const char* expected; 1758 const char* expected;
1758 } path_cases[] = { 1759 } path_cases[] = {
1759 {"javascript:", "javascript:"}, 1760 {"javascript:", true, "javascript:"},
1760 {"JavaScript:Foo", "javascript:Foo"}, 1761 {"JavaScript:Foo", true, "javascript:Foo"},
1761 {":\":This /is interesting;?#", ":\":This /is interesting;?#"}, 1762 {":\":This /is interesting;?#", false, ":\":This /is interesting;?#"},
Peter Kasting 2016/09/29 04:54:12 Should this have instead dropped the initial colon
1762 }; 1763 };
1763 1764
1764 for (size_t i = 0; i < arraysize(path_cases); i++) { 1765 for (size_t i = 0; i < arraysize(path_cases); i++) {
1765 int url_len = static_cast<int>(strlen(path_cases[i].input)); 1766 int url_len = static_cast<int>(strlen(path_cases[i].input));
1766 Parsed parsed; 1767 Parsed parsed;
1767 ParsePathURL(path_cases[i].input, url_len, true, &parsed); 1768 ParsePathURL(path_cases[i].input, url_len, true, &parsed);
1768 1769
1769 Parsed out_parsed; 1770 Parsed out_parsed;
1770 std::string out_str; 1771 std::string out_str;
1771 StdStringCanonOutput output(&out_str); 1772 StdStringCanonOutput output(&out_str);
1772 bool success = CanonicalizePathURL(path_cases[i].input, url_len, parsed, 1773 bool success = CanonicalizePathURL(path_cases[i].input, url_len, parsed,
1773 &output, &out_parsed); 1774 &output, &out_parsed);
1774 output.Complete(); 1775 output.Complete();
1775 1776
1776 EXPECT_TRUE(success); 1777 EXPECT_EQ(path_cases[i].expected_success, success);
1777 EXPECT_EQ(path_cases[i].expected, out_str); 1778 EXPECT_EQ(path_cases[i].expected, out_str);
1778 1779
1779 EXPECT_EQ(0, out_parsed.host.begin); 1780 EXPECT_EQ(0, out_parsed.host.begin);
1780 EXPECT_EQ(-1, out_parsed.host.len); 1781 EXPECT_EQ(-1, out_parsed.host.len);
1781 1782
1782 // When we end with a colon at the end, there should be no path. 1783 // When we end with a colon at the end, there should be no path.
1783 if (path_cases[i].input[url_len - 1] == ':') { 1784 if (path_cases[i].input[url_len - 1] == ':') {
1784 EXPECT_EQ(0, out_parsed.GetContent().begin); 1785 EXPECT_EQ(0, out_parsed.GetContent().begin);
1785 EXPECT_EQ(-1, out_parsed.GetContent().len); 1786 EXPECT_EQ(-1, out_parsed.GetContent().len);
1786 } 1787 }
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 repl_output.Complete(); 2167 repl_output.Complete();
2167 2168
2168 // Generate the expected string and check. 2169 // Generate the expected string and check.
2169 std::string expected("file:///foo?"); 2170 std::string expected("file:///foo?");
2170 for (size_t i = 0; i < new_query.length(); i++) 2171 for (size_t i = 0; i < new_query.length(); i++)
2171 expected.push_back('a'); 2172 expected.push_back('a');
2172 EXPECT_TRUE(expected == repl_str); 2173 EXPECT_TRUE(expected == repl_str);
2173 } 2174 }
2174 2175
2175 } // namespace url 2176 } // namespace url
OLDNEW
« url/url_canon_etc.cc ('K') | « url/url_canon_etc.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698