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

Side by Side Diff: src/url_util_unittest.cc

Issue 1558030: Canonicalize URL before using Extractscheme in DoFindAndCompareScheme functio... (Closed) Base URL: http://google-url.googlecode.com/svn/trunk/
Patch Set: '' Created 10 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/url_util.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 2008, Google Inc. 1 // Copyright 2008, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 // When there is an empty scheme, it should match the empty scheme. 58 // When there is an empty scheme, it should match the empty scheme.
59 const char kStr3[] = ":foo.com/"; 59 const char kStr3[] = ":foo.com/";
60 EXPECT_TRUE(url_util::FindAndCompareScheme( 60 EXPECT_TRUE(url_util::FindAndCompareScheme(
61 kStr3, static_cast<int>(strlen(kStr3)), "", &found_scheme)); 61 kStr3, static_cast<int>(strlen(kStr3)), "", &found_scheme));
62 EXPECT_TRUE(found_scheme == url_parse::Component(0, 0)); 62 EXPECT_TRUE(found_scheme == url_parse::Component(0, 0));
63 63
64 // But when there is no scheme, it should fail. 64 // But when there is no scheme, it should fail.
65 EXPECT_FALSE(url_util::FindAndCompareScheme("", 0, "", &found_scheme)); 65 EXPECT_FALSE(url_util::FindAndCompareScheme("", 0, "", &found_scheme));
66 EXPECT_TRUE(found_scheme == url_parse::Component()); 66 EXPECT_TRUE(found_scheme == url_parse::Component());
67
68 // When there is a ctrl char in scheme, it should canonicalize the url before
69 // comparison.
70 const char ctrlStr[] = " \r\n\tjav\ra\nscri\tpt:alert(1)";
71 EXPECT_TRUE(url_util::FindAndCompareScheme(
72 ctrlStr, static_cast<int>(strlen(ctrlStr)), "javascript", &found_scheme));
73 EXPECT_TRUE(found_scheme == url_parse::Component(1, 10));
67 } 74 }
68 75
69 TEST(URLUtilTest, ReplaceComponents) { 76 TEST(URLUtilTest, ReplaceComponents) {
70 url_parse::Parsed parsed; 77 url_parse::Parsed parsed;
71 url_canon::RawCanonOutputT<char> output; 78 url_canon::RawCanonOutputT<char> output;
72 url_parse::Parsed new_parsed; 79 url_parse::Parsed new_parsed;
73 80
74 // Check that the following calls do not cause crash 81 // Check that the following calls do not cause crash
75 url_canon::Replacements<char> replacements; 82 url_canon::Replacements<char> replacements;
76 replacements.SetRef("test", url_parse::Component(0, 4)); 83 replacements.SetRef("test", url_parse::Component(0, 4));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Magic Windows drive letter behavior when converting to a file URL. 144 // Magic Windows drive letter behavior when converting to a file URL.
138 EXPECT_EQ("file:///E:/foo/", 145 EXPECT_EQ("file:///E:/foo/",
139 CheckReplaceScheme("http://localhost/e:foo/", "file")); 146 CheckReplaceScheme("http://localhost/e:foo/", "file"));
140 #endif 147 #endif
141 148
142 // This will probably change to "about://google.com/" when we fix 149 // This will probably change to "about://google.com/" when we fix
143 // http://crbug.com/160 which should also be an acceptable result. 150 // http://crbug.com/160 which should also be an acceptable result.
144 EXPECT_EQ("about://google.com/", 151 EXPECT_EQ("about://google.com/",
145 CheckReplaceScheme("http://google.com/", "about")); 152 CheckReplaceScheme("http://google.com/", "about"));
146 } 153 }
OLDNEW
« no previous file with comments | « src/url_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698