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

Unified Diff: chrome/browser/autocomplete/zero_suggest_provider.cc

Issue 96753004: Ensure zero suggest can handle XSSI-escaped output. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/zero_suggest_provider.cc
diff --git a/chrome/browser/autocomplete/zero_suggest_provider.cc b/chrome/browser/autocomplete/zero_suggest_provider.cc
index 07d7c2c6ebacfcd7e34db58544981648fd5c9732..089e4256751eb46d21e16230bbf1e7c525162e10 100644
--- a/chrome/browser/autocomplete/zero_suggest_provider.cc
+++ b/chrome/browser/autocomplete/zero_suggest_provider.cc
@@ -133,11 +133,24 @@ void ZeroSuggestProvider::OnURLFetchComplete(const net::URLFetcher* source) {
source->GetStatus().is_success() && source->GetResponseCode() == 200;
if (request_succeeded) {
- JSONStringValueSerializer deserializer(json_data);
- deserializer.set_allow_trailing_comma(true);
- scoped_ptr<Value> data(deserializer.Deserialize(NULL, NULL));
- if (data.get())
- ParseSuggestResults(*data.get());
+ // The JSON response should be an array.
+ for (size_t response_start_index = json_data.find("["), i = 0;
H Fung 2013/11/30 00:46:27 I'm not sure why we try up to 5 times and why we i
+ response_start_index != std::string::npos && i < 5;
+ response_start_index = json_data.find("[", 1), i++) {
+ // Remove any XSSI guards to allow for JSON parsing.
+ if (response_start_index > 0)
+ json_data.erase(0, response_start_index);
+
+ JSONStringValueSerializer deserializer(json_data);
+ deserializer.set_allow_trailing_comma(true);
+ int error_code = 0;
+ scoped_ptr<Value> data(deserializer.Deserialize(&error_code, NULL));
+ if (error_code == 0) {
+ if (data.get())
+ ParseSuggestResults(*data.get());
+ break;
+ }
+ }
}
done_ = true;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698