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

Side by Side Diff: net/base/net_util_icu.cc

Issue 1215933004: New new versions of Starts/EndsWith and SplitString in net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@starts_with
Patch Set: Created 5 years, 5 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 "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/i18n/time_formatting.h" 10 #include "base/i18n/time_formatting.h"
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 new_parsed = &parsed_temp; 672 new_parsed = &parsed_temp;
673 else 673 else
674 *new_parsed = url::Parsed(); 674 *new_parsed = url::Parsed();
675 675
676 // Special handling for view-source:. Don't use content::kViewSourceScheme 676 // Special handling for view-source:. Don't use content::kViewSourceScheme
677 // because this library shouldn't depend on chrome. 677 // because this library shouldn't depend on chrome.
678 const char kViewSource[] = "view-source"; 678 const char kViewSource[] = "view-source";
679 // Reject "view-source:view-source:..." to avoid deep recursion. 679 // Reject "view-source:view-source:..." to avoid deep recursion.
680 const char kViewSourceTwice[] = "view-source:view-source:"; 680 const char kViewSourceTwice[] = "view-source:view-source:";
681 if (url.SchemeIs(kViewSource) && 681 if (url.SchemeIs(kViewSource) &&
682 !base::StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice, 682 !base::StartsWith(url.possibly_invalid_spec(), kViewSourceTwice,
683 false)) { 683 base::CompareCase::INSENSITIVE_ASCII)) {
684 return FormatViewSourceUrl(url, languages, format_types, 684 return FormatViewSourceUrl(url, languages, format_types,
685 unescape_rules, new_parsed, prefix_end, 685 unescape_rules, new_parsed, prefix_end,
686 adjustments); 686 adjustments);
687 } 687 }
688 688
689 // We handle both valid and invalid URLs (this will give us the spec 689 // We handle both valid and invalid URLs (this will give us the spec
690 // regardless of validity). 690 // regardless of validity).
691 const std::string& spec = url.possibly_invalid_spec(); 691 const std::string& spec = url.possibly_invalid_spec();
692 const url::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); 692 const url::Parsed& parsed = url.parsed_for_possibly_invalid_spec();
693 693
694 // Scheme & separators. These are ASCII. 694 // Scheme & separators. These are ASCII.
695 base::string16 url_string; 695 base::string16 url_string;
696 url_string.insert( 696 url_string.insert(
697 url_string.end(), spec.begin(), 697 url_string.end(), spec.begin(),
698 spec.begin() + parsed.CountCharactersBefore(url::Parsed::USERNAME, true)); 698 spec.begin() + parsed.CountCharactersBefore(url::Parsed::USERNAME, true));
699 const char kHTTP[] = "http://"; 699 const char kHTTP[] = "http://";
700 const char kFTP[] = "ftp."; 700 const char kFTP[] = "ftp.";
701 // url_fixer::FixupURL() treats "ftp.foo.com" as ftp://ftp.foo.com. This 701 // url_fixer::FixupURL() treats "ftp.foo.com" as ftp://ftp.foo.com. This
702 // means that if we trim "http://" off a URL whose host starts with "ftp." and 702 // means that if we trim "http://" off a URL whose host starts with "ftp." and
703 // the user inputs this into any field subject to fixup (which is basically 703 // the user inputs this into any field subject to fixup (which is basically
704 // all input fields), the meaning would be changed. (In fact, often the 704 // all input fields), the meaning would be changed. (In fact, often the
705 // formatted URL is directly pre-filled into an input field.) For this reason 705 // formatted URL is directly pre-filled into an input field.) For this reason
706 // we avoid stripping "http://" in this case. 706 // we avoid stripping "http://" in this case.
707 bool omit_http = (format_types & kFormatUrlOmitHTTP) && 707 bool omit_http =
708 base::EqualsASCII(url_string, kHTTP) && 708 (format_types & kFormatUrlOmitHTTP) &&
709 !base::StartsWithASCII(url.host(), kFTP, true); 709 base::EqualsASCII(url_string, kHTTP) &&
710 !base::StartsWith(url.host(), kFTP, base::CompareCase::SENSITIVE);
710 new_parsed->scheme = parsed.scheme; 711 new_parsed->scheme = parsed.scheme;
711 712
712 // Username & password. 713 // Username & password.
713 if ((format_types & kFormatUrlOmitUsernamePassword) != 0) { 714 if ((format_types & kFormatUrlOmitUsernamePassword) != 0) {
714 // Remove the username and password fields. We don't want to display those 715 // Remove the username and password fields. We don't want to display those
715 // to the user since they can be used for attacks, 716 // to the user since they can be used for attacks,
716 // e.g. "http://google.com:search@evil.ru/" 717 // e.g. "http://google.com:search@evil.ru/"
717 new_parsed->username.reset(); 718 new_parsed->username.reset();
718 new_parsed->password.reset(); 719 new_parsed->password.reset();
719 // Update the adjustments based on removed username and/or password. 720 // Update the adjustments based on removed username and/or password.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 if (offset_for_adjustment) 830 if (offset_for_adjustment)
830 offsets.push_back(*offset_for_adjustment); 831 offsets.push_back(*offset_for_adjustment);
831 base::string16 result = FormatUrlWithOffsets(url, languages, format_types, 832 base::string16 result = FormatUrlWithOffsets(url, languages, format_types,
832 unescape_rules, new_parsed, prefix_end, &offsets); 833 unescape_rules, new_parsed, prefix_end, &offsets);
833 if (offset_for_adjustment) 834 if (offset_for_adjustment)
834 *offset_for_adjustment = offsets[0]; 835 *offset_for_adjustment = offsets[0];
835 return result; 836 return result;
836 } 837 }
837 838
838 } // namespace net 839 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698