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(), |