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

Side by Side Diff: components/url_formatter/url_fixer.cc

Issue 2378213002: Mark URLs with empty schemes as invalid. (Closed)
Patch Set: Comments 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/url_formatter/url_fixer.h" 5 #include "components/url_formatter/url_fixer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 473
474 // We need to add a scheme in order for ParseStandardURL to be happy. 474 // We need to add a scheme in order for ParseStandardURL to be happy.
475 // Find the first non-whitespace character. 475 // Find the first non-whitespace character.
476 std::string::iterator first_nonwhite = text->begin(); 476 std::string::iterator first_nonwhite = text->begin();
477 while ((first_nonwhite != text->end()) && 477 while ((first_nonwhite != text->end()) &&
478 base::IsUnicodeWhitespace(*first_nonwhite)) 478 base::IsUnicodeWhitespace(*first_nonwhite))
479 ++first_nonwhite; 479 ++first_nonwhite;
480 480
481 // Construct the text to parse by inserting the scheme. 481 // Construct the text to parse by inserting the scheme.
482 std::string inserted_text(scheme); 482 std::string inserted_text(scheme);
483 inserted_text.append(url::kStandardSchemeSeparator); 483 // Assume a leading colon was meant to be a scheme separator (which GURL will
484 // fix up for us into the full "://"). Otherwise add the separator ourselves.
485 if (first_nonwhite == text->end() || *first_nonwhite != ':')
486 inserted_text.append(url::kStandardSchemeSeparator);
484 std::string text_to_parse(text->begin(), first_nonwhite); 487 std::string text_to_parse(text->begin(), first_nonwhite);
485 text_to_parse.append(inserted_text); 488 text_to_parse.append(inserted_text);
486 text_to_parse.append(first_nonwhite, text->end()); 489 text_to_parse.append(first_nonwhite, text->end());
487 490
488 // Have the GURL parser do the heavy lifting for us. 491 // Have the GURL parser do the heavy lifting for us.
489 url::ParseStandardURL(text_to_parse.data(), 492 url::ParseStandardURL(text_to_parse.data(),
490 static_cast<int>(text_to_parse.length()), parts); 493 static_cast<int>(text_to_parse.length()), parts);
491 494
492 // Offset the results of the parse to match the original text. 495 // Offset the results of the parse to match the original text.
493 const int offset = -static_cast<int>(inserted_text.length()); 496 const int offset = -static_cast<int>(inserted_text.length());
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } 678 }
676 679
677 bool IsEquivalentScheme(const std::string& scheme1, 680 bool IsEquivalentScheme(const std::string& scheme1,
678 const std::string& scheme2) { 681 const std::string& scheme2) {
679 return scheme1 == scheme2 || 682 return scheme1 == scheme2 ||
680 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || 683 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) ||
681 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); 684 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme);
682 } 685 }
683 686
684 } // namespace url_formatter 687 } // namespace url_formatter
OLDNEW
« no previous file with comments | « components/omnibox/browser/autocomplete_input_unittest.cc ('k') | components/url_formatter/url_fixer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698