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

Unified Diff: net/proxy/proxy_script_fetcher.cc

Issue 210028: Respect the charset specified in PAC file responses. ProxyScriptFetcher is no... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: re-order parameter so output is last Created 11 years, 3 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 | « net/proxy/proxy_script_fetcher.h ('k') | net/proxy/proxy_script_fetcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_script_fetcher.cc
===================================================================
--- net/proxy/proxy_script_fetcher.cc (revision 26789)
+++ net/proxy/proxy_script_fetcher.cc (working copy)
@@ -43,6 +43,30 @@
return false;
}
+// Convert |bytes| (which is encoded by |charset|) in place to UTF8.
+// If |charset| is empty, then we don't know what it was and guess.
+void ConvertResponseToUTF8(const std::string& charset, std::string* bytes) {
+ const char* codepage;
+
+ if (charset.empty()) {
+ // Assume ISO-8859-1 if no charset was specified.
+ codepage = "ISO-8859-1";
+ } else {
+ // Otherwise trust the charset that was provided.
+ codepage = charset.c_str();
+ }
+
+ // We will be generous in the conversion -- if any characters lie
+ // outside of |charset| (i.e. invalid), then substitute them with
+ // U+FFFD rather than failing.
+ std::wstring tmp_wide;
+ CodepageToWide(*bytes, codepage,
+ OnStringUtilConversionError::SUBSTITUTE,
+ &tmp_wide);
+ // TODO(eroman): would be nice to have a CodepageToUTF8() function.
+ *bytes = WideToUTF8(tmp_wide);
+}
+
} // namespace
class ProxyScriptFetcherImpl : public ProxyScriptFetcher,
@@ -273,9 +297,15 @@
}
void ProxyScriptFetcherImpl::FetchCompleted() {
- // On error, the caller expects empty string for bytes.
- if (result_code_ != OK)
+ if (result_code_ == OK) {
+ // The caller expects the response to be encoded as UTF8.
+ std::string charset;
+ cur_request_->GetCharset(&charset);
+ ConvertResponseToUTF8(charset, result_bytes_);
+ } else {
+ // On error, the caller expects empty string for bytes.
result_bytes_->clear();
+ }
int result_code = result_code_;
CompletionCallback* callback = callback_;
« no previous file with comments | « net/proxy/proxy_script_fetcher.h ('k') | net/proxy/proxy_script_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698