Empty value in query should trigger safe search
When query in the search contains empty value, it should be
considered as a search query. Otherwise that is a possibility for safe
search escape.
Bug: chromium:787981
Test: Unit test.
Change-Id: I341b1821f9db5b8b0f8cc0aad9e5f714b706c5ce
Reviewed-on: https://chromium-review.googlesource.com/793714
Reviewed-by: Zhongyi Shi <zhongyi@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Igor <igorcov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520483}
diff --git a/chrome/browser/net/safe_search_util_unittest.cc b/chrome/browser/net/safe_search_util_unittest.cc
index d52f14d..bfd0b2d1 100644
--- a/chrome/browser/net/safe_search_util_unittest.cc
+++ b/chrome/browser/net/safe_search_util_unittest.cc
@@ -117,6 +117,9 @@
CheckAddedParameters("http://google.de/?q=goog&safe=off&ssui=off",
"q=goog&" + kBothParameters);
+ CheckAddedParameters("http://google.de/?q=&tbs=rimg:",
+ "q=&tbs=rimg:&" + kBothParameters);
+
// Test various combinations where we should not add anything.
CheckAddedParameters("http://google.com/?q=goog&" + kSsuiParameter + "&" +
kSafeParameter,
diff --git a/components/google/core/browser/google_util.cc b/components/google/core/browser/google_util.cc
index 845e22a6..2820e03 100644
--- a/components/google/core/browser/google_util.cc
+++ b/components/google/core/browser/google_util.cc
@@ -142,11 +142,9 @@
bool HasGoogleSearchQueryParam(base::StringPiece str) {
url::Component query(0, static_cast<int>(str.length())), key, value;
while (url::ExtractQueryKeyValue(str.data(), &query, &key, &value)) {
- if (value.is_nonempty()) {
- base::StringPiece key_str = str.substr(key.begin, key.len);
- if (key_str == "q" || key_str == "as_q")
- return true;
- }
+ base::StringPiece key_str = str.substr(key.begin, key.len);
+ if (key_str == "q" || key_str == "as_q")
+ return true;
}
return false;
}
diff --git a/components/google/core/browser/google_util_unittest.cc b/components/google/core/browser/google_util_unittest.cc
index 46072bf5..477d3ae 100644
--- a/components/google/core/browser/google_util_unittest.cc
+++ b/components/google/core/browser/google_util_unittest.cc
@@ -147,6 +147,8 @@
"%s://www.google.co.uk/search?%s=something",
// It's actually valid for both to have the query parameter.
"%s://www.google.com/search?%s=something#q=other",
+ // Also valid to have an empty query parameter
+ "%s://www.google.com/search?%s=",
// Queries with path "/webhp", "/" or "" need to have the query parameter
// in the hash fragment.
@@ -216,12 +218,6 @@
}
const std::string patterns_q[] = {
- // Can't have an empty query parameter.
- "%s://www.google.com/search?%s=",
- "%s://www.google.com/search?name=bob&%s=",
- "%s://www.google.com/webhp#%s=",
- "%s://www.google.com/webhp#name=bob&%s=",
-
// Home page searches without a hash fragment query parameter are invalid.
"%s://www.google.com/webhp?%s=something",
"%s://www.google.com/webhp?%s=something#no=good",