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

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

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 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
« no previous file with comments | « net/base/net_util.cc ('k') | net/base/network_activity_monitor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 600 }
601 if (is_dir) { 601 if (is_dir) {
602 result.append(",1,"); 602 result.append(",1,");
603 } else { 603 } else {
604 result.append(",0,"); 604 result.append(",0,");
605 } 605 }
606 606
607 // Negative size means unknown or not applicable (e.g. directory). 607 // Negative size means unknown or not applicable (e.g. directory).
608 base::string16 size_string; 608 base::string16 size_string;
609 if (size >= 0) 609 if (size >= 0)
610 size_string = FormatBytesUnlocalized(size); 610 size_string = base::FormatBytesUnlocalized(size);
611 base::EscapeJSONString(size_string, true, &result); 611 base::EscapeJSONString(size_string, true, &result);
612 612
613 result.append(","); 613 result.append(",");
614 614
615 base::string16 modified_str; 615 base::string16 modified_str;
616 // |modified| can be NULL in FTP listings. 616 // |modified| can be NULL in FTP listings.
617 if (!modified.is_null()) { 617 if (!modified.is_null()) {
618 modified_str = base::TimeFormatShortDateAndTime(modified); 618 modified_str = base::TimeFormatShortDateAndTime(modified);
619 } 619 }
620 base::EscapeJSONString(modified_str, true, &result); 620 base::EscapeJSONString(modified_str, true, &result);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 new_parsed = &parsed_temp; 669 new_parsed = &parsed_temp;
670 else 670 else
671 *new_parsed = url::Parsed(); 671 *new_parsed = url::Parsed();
672 672
673 // Special handling for view-source:. Don't use content::kViewSourceScheme 673 // Special handling for view-source:. Don't use content::kViewSourceScheme
674 // because this library shouldn't depend on chrome. 674 // because this library shouldn't depend on chrome.
675 const char kViewSource[] = "view-source"; 675 const char kViewSource[] = "view-source";
676 // Reject "view-source:view-source:..." to avoid deep recursion. 676 // Reject "view-source:view-source:..." to avoid deep recursion.
677 const char kViewSourceTwice[] = "view-source:view-source:"; 677 const char kViewSourceTwice[] = "view-source:view-source:";
678 if (url.SchemeIs(kViewSource) && 678 if (url.SchemeIs(kViewSource) &&
679 !StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice, false)) { 679 !base::StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice,
680 false)) {
680 return FormatViewSourceUrl(url, languages, format_types, 681 return FormatViewSourceUrl(url, languages, format_types,
681 unescape_rules, new_parsed, prefix_end, 682 unescape_rules, new_parsed, prefix_end,
682 adjustments); 683 adjustments);
683 } 684 }
684 685
685 // We handle both valid and invalid URLs (this will give us the spec 686 // We handle both valid and invalid URLs (this will give us the spec
686 // regardless of validity). 687 // regardless of validity).
687 const std::string& spec = url.possibly_invalid_spec(); 688 const std::string& spec = url.possibly_invalid_spec();
688 const url::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); 689 const url::Parsed& parsed = url.parsed_for_possibly_invalid_spec();
689 690
690 // Scheme & separators. These are ASCII. 691 // Scheme & separators. These are ASCII.
691 base::string16 url_string; 692 base::string16 url_string;
692 url_string.insert( 693 url_string.insert(
693 url_string.end(), spec.begin(), 694 url_string.end(), spec.begin(),
694 spec.begin() + parsed.CountCharactersBefore(url::Parsed::USERNAME, true)); 695 spec.begin() + parsed.CountCharactersBefore(url::Parsed::USERNAME, true));
695 const char kHTTP[] = "http://"; 696 const char kHTTP[] = "http://";
696 const char kFTP[] = "ftp."; 697 const char kFTP[] = "ftp.";
697 // url_fixer::FixupURL() treats "ftp.foo.com" as ftp://ftp.foo.com. This 698 // url_fixer::FixupURL() treats "ftp.foo.com" as ftp://ftp.foo.com. This
698 // means that if we trim "http://" off a URL whose host starts with "ftp." and 699 // means that if we trim "http://" off a URL whose host starts with "ftp." and
699 // the user inputs this into any field subject to fixup (which is basically 700 // the user inputs this into any field subject to fixup (which is basically
700 // all input fields), the meaning would be changed. (In fact, often the 701 // all input fields), the meaning would be changed. (In fact, often the
701 // formatted URL is directly pre-filled into an input field.) For this reason 702 // formatted URL is directly pre-filled into an input field.) For this reason
702 // we avoid stripping "http://" in this case. 703 // we avoid stripping "http://" in this case.
703 bool omit_http = (format_types & kFormatUrlOmitHTTP) && 704 bool omit_http = (format_types & kFormatUrlOmitHTTP) &&
704 EqualsASCII(url_string, kHTTP) && 705 EqualsASCII(url_string, kHTTP) &&
705 !StartsWithASCII(url.host(), kFTP, true); 706 !base::StartsWithASCII(url.host(), kFTP, true);
706 new_parsed->scheme = parsed.scheme; 707 new_parsed->scheme = parsed.scheme;
707 708
708 // Username & password. 709 // Username & password.
709 if ((format_types & kFormatUrlOmitUsernamePassword) != 0) { 710 if ((format_types & kFormatUrlOmitUsernamePassword) != 0) {
710 // Remove the username and password fields. We don't want to display those 711 // Remove the username and password fields. We don't want to display those
711 // to the user since they can be used for attacks, 712 // to the user since they can be used for attacks,
712 // e.g. "http://google.com:search@evil.ru/" 713 // e.g. "http://google.com:search@evil.ru/"
713 new_parsed->username.reset(); 714 new_parsed->username.reset();
714 new_parsed->password.reset(); 715 new_parsed->password.reset();
715 // Update the adjustments based on removed username and/or password. 716 // Update the adjustments based on removed username and/or password.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 &url_string, &new_parsed->query, adjustments); 783 &url_string, &new_parsed->query, adjustments);
783 784
784 // Ref. This is valid, unescaped UTF-8, so we can just convert. 785 // Ref. This is valid, unescaped UTF-8, so we can just convert.
785 if (parsed.ref.is_valid()) 786 if (parsed.ref.is_valid())
786 url_string.push_back('#'); 787 url_string.push_back('#');
787 AppendFormattedComponent(spec, parsed.ref, 788 AppendFormattedComponent(spec, parsed.ref,
788 NonHostComponentTransform(UnescapeRule::NONE), 789 NonHostComponentTransform(UnescapeRule::NONE),
789 &url_string, &new_parsed->ref, adjustments); 790 &url_string, &new_parsed->ref, adjustments);
790 791
791 // If we need to strip out http do it after the fact. 792 // If we need to strip out http do it after the fact.
792 if (omit_http && StartsWith(url_string, base::ASCIIToUTF16(kHTTP), true)) { 793 if (omit_http && base::StartsWith(url_string, base::ASCIIToUTF16(kHTTP),
794 base::CompareCase::SENSITIVE)) {
793 const size_t kHTTPSize = arraysize(kHTTP) - 1; 795 const size_t kHTTPSize = arraysize(kHTTP) - 1;
794 url_string = url_string.substr(kHTTPSize); 796 url_string = url_string.substr(kHTTPSize);
795 // Because offsets in the |adjustments| are already calculated with respect 797 // Because offsets in the |adjustments| are already calculated with respect
796 // to the string with the http:// prefix in it, those offsets remain correct 798 // to the string with the http:// prefix in it, those offsets remain correct
797 // after stripping the prefix. The only thing necessary is to add an 799 // after stripping the prefix. The only thing necessary is to add an
798 // adjustment to reflect the stripped prefix. 800 // adjustment to reflect the stripped prefix.
799 adjustments->insert(adjustments->begin(), 801 adjustments->insert(adjustments->begin(),
800 base::OffsetAdjuster::Adjustment(0, kHTTPSize, 0)); 802 base::OffsetAdjuster::Adjustment(0, kHTTPSize, 0));
801 803
802 if (prefix_end) 804 if (prefix_end)
(...skipping 20 matching lines...) Expand all
823 if (offset_for_adjustment) 825 if (offset_for_adjustment)
824 offsets.push_back(*offset_for_adjustment); 826 offsets.push_back(*offset_for_adjustment);
825 base::string16 result = FormatUrlWithOffsets(url, languages, format_types, 827 base::string16 result = FormatUrlWithOffsets(url, languages, format_types,
826 unescape_rules, new_parsed, prefix_end, &offsets); 828 unescape_rules, new_parsed, prefix_end, &offsets);
827 if (offset_for_adjustment) 829 if (offset_for_adjustment)
828 *offset_for_adjustment = offsets[0]; 830 *offset_for_adjustment = offsets[0];
829 return result; 831 return result;
830 } 832 }
831 833
832 } // namespace net 834 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util.cc ('k') | net/base/network_activity_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698