OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "components/safe_browsing_db/util.h" | 5 #include "components/safe_browsing_db/util.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "crypto/sha2.h" | 8 #include "crypto/sha2.h" |
9 #include "net/base/escape.h" | 9 #include "net/base/escape.h" |
10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 f_replacements.ClearPassword(); | 223 f_replacements.ClearPassword(); |
224 url_without_fragment = url.ReplaceComponents(f_replacements); | 224 url_without_fragment = url.ReplaceComponents(f_replacements); |
225 | 225 |
226 // 2. Do URL unescaping until no more hex encoded characters exist. | 226 // 2. Do URL unescaping until no more hex encoded characters exist. |
227 std::string url_unescaped_str(Unescape(url_without_fragment.spec())); | 227 std::string url_unescaped_str(Unescape(url_without_fragment.spec())); |
228 url::Parsed parsed; | 228 url::Parsed parsed; |
229 url::ParseStandardURL(url_unescaped_str.data(), url_unescaped_str.length(), | 229 url::ParseStandardURL(url_unescaped_str.data(), url_unescaped_str.length(), |
230 &parsed); | 230 &parsed); |
231 | 231 |
232 // 3. In hostname, remove all leading and trailing dots. | 232 // 3. In hostname, remove all leading and trailing dots. |
233 const std::string host = | 233 base::StringPiece host; |
234 (parsed.host.len > 0) | 234 if (parsed.host.len > 0) |
235 ? url_unescaped_str.substr(parsed.host.begin, parsed.host.len) | 235 host.set(url_unescaped_str.data() + parsed.host.begin, parsed.host.len); |
236 : std::string(); | 236 |
237 std::string host_without_end_dots; | 237 base::StringPiece host_without_end_dots = |
238 base::TrimString(host, ".", &host_without_end_dots); | 238 base::TrimString(host, ".", base::TrimPositions::TRIM_ALL); |
239 | 239 |
240 // 4. In hostname, replace consecutive dots with a single dot. | 240 // 4. In hostname, replace consecutive dots with a single dot. |
241 std::string host_without_consecutive_dots(RemoveConsecutiveChars( | 241 std::string host_without_consecutive_dots(RemoveConsecutiveChars( |
242 host_without_end_dots, '.')); | 242 host_without_end_dots, '.')); |
243 | 243 |
244 // 5. In path, replace runs of consecutive slashes with a single slash. | 244 // 5. In path, replace runs of consecutive slashes with a single slash. |
245 std::string path = | 245 base::StringPiece path; |
246 (parsed.path.len > 0) | 246 if (parsed.path.len > 0) |
247 ? url_unescaped_str.substr(parsed.path.begin, parsed.path.len) | 247 path.set(url_unescaped_str.data() + parsed.path.begin, parsed.path.len); |
248 : std::string(); | |
249 std::string path_without_consecutive_slash(RemoveConsecutiveChars(path, '/')); | 248 std::string path_without_consecutive_slash(RemoveConsecutiveChars(path, '/')); |
250 | 249 |
251 url::Replacements<char> hp_replacements; | 250 url::Replacements<char> hp_replacements; |
252 hp_replacements.SetHost( | 251 hp_replacements.SetHost( |
253 host_without_consecutive_dots.data(), | 252 host_without_consecutive_dots.data(), |
254 url::Component(0, host_without_consecutive_dots.length())); | 253 url::Component(0, host_without_consecutive_dots.length())); |
255 hp_replacements.SetPath( | 254 hp_replacements.SetPath( |
256 path_without_consecutive_slash.data(), | 255 path_without_consecutive_slash.data(), |
257 url::Component(0, path_without_consecutive_slash.length())); | 256 url::Component(0, path_without_consecutive_slash.length())); |
258 | 257 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 GenerateHostsToCheck(url, &hosts); | 366 GenerateHostsToCheck(url, &hosts); |
368 GeneratePathsToCheck(url, &paths); | 367 GeneratePathsToCheck(url, &paths); |
369 for (size_t h = 0; h < hosts.size(); ++h) { | 368 for (size_t h = 0; h < hosts.size(); ++h) { |
370 for (size_t p = 0; p < paths.size(); ++p) { | 369 for (size_t p = 0; p < paths.size(); ++p) { |
371 urls->push_back(hosts[h] + paths[p]); | 370 urls->push_back(hosts[h] + paths[p]); |
372 } | 371 } |
373 } | 372 } |
374 } | 373 } |
375 | 374 |
376 } // namespace safe_browsing | 375 } // namespace safe_browsing |
OLD | NEW |