Commit 7c10eab1 authored by manuk's avatar manuk Committed by Commit Bot

[Omnibox] Avoid removing the `www.` prefix during deduping when doing so would...

[Omnibox] Avoid removing the `www.` prefix during deduping when doing so would leave no host component.

When sorting and deduping matches, match GURLs are stripped (`AutocompleteMatch::GURLToStrippedGURL`). Certain omnibox inputs, such as `http://www.` without inline autocomplete, produce matches with host compoments `www.`. Stripping `www.` in these cases would result in an empty url host component and, therefore, invalid `GURL`. Invoking `GURL::spec` on such invalid URLs would then cause a DCHECK to evaluate false and crash the browser. The crash only affects debug builds as the DCHECK is inactive for non-debug builds.

Bug: 898554
Change-Id: I73461c65ba53891d6f3b52bc767c754b02c1ce3e
Reviewed-on: https://chromium-review.googlesource.com/c/1331631
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607709}
parent 61720441
......@@ -521,7 +521,7 @@ GURL AutocompleteMatch::GURLToStrippedGURL(
static const char prefix[] = "www.";
static const size_t prefix_len = arraysize(prefix) - 1;
std::string host = stripped_destination_url.host();
if (host.compare(0, prefix_len, prefix) == 0) {
if (host.compare(0, prefix_len, prefix) == 0 && host.length() > prefix_len) {
replacements.SetHostStr(base::StringPiece(host).substr(prefix_len));
needs_replacement = true;
}
......
......@@ -374,6 +374,9 @@ TEST(AutocompleteMatchTest, Duplicates) {
"https://xn--1lq90ic7f1rc.cn/", false },
{ L"http://\x89c6 x", "http://xn--1lq90ic7f1rc.cn/",
"https://xn--1lq90ic7f1rc.cn/", true },
// URLs with hosts containing only `www.` should produce valid stripped urls
{ L"http://www./", "http://www./", "http://google.com/", false },
};
for (size_t i = 0; i < arraysize(cases); ++i) {
......@@ -392,5 +395,7 @@ TEST(AutocompleteMatchTest, Duplicates) {
m2.ComputeStrippedDestinationURL(input, nullptr);
EXPECT_EQ(cases[i].expected_duplicate,
m1.stripped_destination_url == m2.stripped_destination_url);
EXPECT_TRUE(m1.stripped_destination_url.is_valid());
EXPECT_TRUE(m2.stripped_destination_url.is_valid());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment