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

Unified Diff: net/base/net_util_icu.cc

Issue 493253003: Adds default port handling to FormatUrl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_icu_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util_icu.cc
diff --git a/net/base/net_util_icu.cc b/net/base/net_util_icu.cc
index 4094feeff74a1313e900940ea4d6648c42f0e2a2..528c6d554a4a9c25f1204679b81bec11c394fe6d 100644
--- a/net/base/net_util_icu.cc
+++ b/net/base/net_util_icu.cc
@@ -576,6 +576,7 @@ const FormatUrlType kFormatUrlOmitHTTP = 1 << 1;
const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2;
const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword |
kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname;
+const FormatUrlType kFormatUrlOmitDefaultPort = 1 << 3;
base::string16 IDNToUnicode(const std::string& host,
const std::string& languages) {
@@ -749,8 +750,22 @@ base::string16 FormatUrlWithAdjustments(
AppendFormattedComponent(spec, parsed.host, HostComponentTransform(languages),
&url_string, &new_parsed->host, adjustments);
- // Port.
- if (parsed.port.is_nonempty()) {
+ // Port. Can omit port if it matches the default port for the scheme.
+ bool port_needs_reset = !parsed.port.is_nonempty();
+ if (!port_needs_reset && format_types & kFormatUrlOmitDefaultPort) {
Ryan Sleevi 2014/08/25 04:16:37 Put this bitmask in () (format_type & kFormatUrlO
+ int port = url::ParsePort(spec.data(), parsed.port);
+ // Intentionally keep the port if there is a parsing error.
+ port_needs_reset =
+ (port == url::PORT_UNSPECIFIED) ||
+ (port == url::DefaultPortForScheme(spec.data() + parsed.scheme.begin,
+ parsed.scheme.len));
+ if (port_needs_reset) {
+ adjustments->push_back(base::OffsetAdjuster::Adjustment(
+ parsed.port.begin, parsed.port.len, 0));
+ }
+ }
+
+ if (!port_needs_reset) {
url_string.push_back(':');
new_parsed->port.begin = url_string.length();
url_string.insert(url_string.end(),
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_icu_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698