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

Unified Diff: url/scheme_host_port.cc

Issue 2387143003: Fix SchemeHostPort::GetURL() and add more tests (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « url/origin_unittest.cc ('k') | url/scheme_host_port_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/scheme_host_port.cc
diff --git a/url/scheme_host_port.cc b/url/scheme_host_port.cc
index b9599865dd9f4e58ef7ffc63802efbad0aa313f4..48cae13a622d0f56d225d815ed236c237ce3d67d 100644
--- a/url/scheme_host_port.cc
+++ b/url/scheme_host_port.cc
@@ -153,6 +153,9 @@ GURL SchemeHostPort::GetURL() const {
url::Parsed parsed;
std::string serialized = SerializeInternal(&parsed);
+ if (IsInvalid())
+ return GURL(std::move(serialized), parsed, false);
+
// If the serialized string is passed to GURL for parsing, it will append an
// empty path "/". Add that here. Note: per RFC 6454 we cannot do this for
// normal Origin serialization.
@@ -177,13 +180,17 @@ std::string SchemeHostPort::SerializeInternal(url::Parsed* parsed) const {
if (IsInvalid())
return result;
- parsed->scheme = Component(0, scheme_.length());
- result.append(scheme_);
+ if (!scheme_.empty()) {
+ parsed->scheme = Component(0, scheme_.length());
+ result.append(scheme_);
+ }
result.append(kStandardSchemeSeparator);
- parsed->host = Component(result.length(), host_.length());
- result.append(host_);
+ if (!host_.empty()) {
+ parsed->host = Component(result.length(), host_.length());
+ result.append(host_);
+ }
if (port_ == 0)
return result;
« no previous file with comments | « url/origin_unittest.cc ('k') | url/scheme_host_port_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698