[url] For empty hosts, just trust GURL to make the invalid/valid decision
The SchemeHostPort always considers tuples with SCHEME_WITHOUT_PORT to
have empty hosts without being invalid (to cater to cases like file
schemes which can have hosts or not).
This led to a mismatch in SchemeHostPost::GetURL where we always
considered URLs with empty hosts to be valid GURLs, but this is not an
assumption that holds true. This CL just punts the valid decision in this
case to GURL for re-parsing, since it should be a rare occurance.
Bug: 820194
Change-Id: I3f4441d8c71a9b9500c71dbe98f0769f42ad13b5
Reviewed-on: https://chromium-review.googlesource.com/956424
Reviewed-by: Mike West <[email protected]>
Commit-Queue: Charlie Harrison <[email protected]>
Cr-Commit-Position: refs/heads/master@{#542527}
diff --git a/url/scheme_host_port_unittest.cc b/url/scheme_host_port_unittest.cc
index ba97a6a..5449ea6 100644
--- a/url/scheme_host_port_unittest.cc
+++ b/url/scheme_host_port_unittest.cc
@@ -9,6 +9,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"
+#include "url/url_util.h"
namespace {
@@ -252,4 +253,21 @@
}
}
+// Some schemes have optional authority. Make sure that GURL conversion from
+// SchemeHostPort is not opinionated in that regard. For more info, See
+// crbug.com/820194, where we considered all SchemeHostPorts with
+// SCHEME_WITHOUT_PORT as valid with empty hosts, even though some are not (e.g.
+// chrome URLs).
+TEST(SchemeHostPortTest, EmptyHostGurlConversion) {
+ url::AddStandardScheme("chrome", url::SCHEME_WITHOUT_PORT);
+
+ GURL chrome_url("chrome:");
+ EXPECT_FALSE(chrome_url.is_valid());
+
+ url::SchemeHostPort chrome_tuple("chrome", "", 0);
+ EXPECT_FALSE(chrome_tuple.GetURL().is_valid());
+ ExpectParsedUrlsEqual(GURL(chrome_tuple.Serialize()), chrome_tuple.GetURL());
+ ExpectParsedUrlsEqual(chrome_url, chrome_tuple.GetURL());
+}
+
} // namespace url