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

Side by Side Diff: net/base/net_util.cc

Issue 4268: IsStringUTF8 unittest and enforcing UTF-8 in JSON deserialization (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/string_util_unittest.cc ('k') | net/base/net_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <unicode/ucnv.h> 6 #include <unicode/ucnv.h>
7 #include <unicode/uidna.h> 7 #include <unicode/uidna.h>
8 #include <unicode/ulocdata.h> 8 #include <unicode/ulocdata.h>
9 #include <unicode/uniset.h> 9 #include <unicode/uniset.h>
10 #include <unicode/uscript.h> 10 #include <unicode/uscript.h>
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 230 }
231 231
232 bool DecodeWord(const std::string& encoded_word, 232 bool DecodeWord(const std::string& encoded_word,
233 bool *is_rfc2047, 233 bool *is_rfc2047,
234 std::string* output) { 234 std::string* output) {
235 // TODO(jungshik) : Revisit this later. Do we want to pass through non-ASCII 235 // TODO(jungshik) : Revisit this later. Do we want to pass through non-ASCII
236 // strings which can be mozibake? WinHTTP converts a raw 8bit string 236 // strings which can be mozibake? WinHTTP converts a raw 8bit string
237 // UTF-16 assuming it's in the OS default encoding. 237 // UTF-16 assuming it's in the OS default encoding.
238 if (!IsStringASCII(encoded_word)) { 238 if (!IsStringASCII(encoded_word)) {
239 // Try falling back to the NativeMB encoding if the raw input is not UTF-8. 239 // Try falling back to the NativeMB encoding if the raw input is not UTF-8.
240 if (IsStringUTF8(encoded_word.c_str())) { 240 if (IsStringUTF8(encoded_word)) {
241 *output = encoded_word; 241 *output = encoded_word;
242 } else { 242 } else {
243 *output = WideToUTF8(base::SysNativeMBToWide(encoded_word)); 243 *output = WideToUTF8(base::SysNativeMBToWide(encoded_word));
244 } 244 }
245 *is_rfc2047 = false; 245 *is_rfc2047 = false;
246 return true; 246 return true;
247 } 247 }
248 248
249 // RFC 2047 : one of encoding methods supported by Firefox and relatively 249 // RFC 2047 : one of encoding methods supported by Firefox and relatively
250 // widely used by web servers. 250 // widely used by web servers.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 322
323 // We're not handling 'especial' characters quoted with '\', but 323 // We're not handling 'especial' characters quoted with '\', but
324 // it should be Ok because we're not an email client but a 324 // it should be Ok because we're not an email client but a
325 // web browser. 325 // web browser.
326 326
327 // What IE6/7 does: %-escaped UTF-8. We could extend this to 327 // What IE6/7 does: %-escaped UTF-8. We could extend this to
328 // support a rudimentary form of RFC 2231 with charset label, but 328 // support a rudimentary form of RFC 2231 with charset label, but
329 // it'd gain us little in terms of compatibility. 329 // it'd gain us little in terms of compatibility.
330 tmp = UnescapeURLComponent(encoded_word, UnescapeRule::SPACES); 330 tmp = UnescapeURLComponent(encoded_word, UnescapeRule::SPACES);
331 if (IsStringUTF8(tmp.c_str())) { 331 if (IsStringUTF8(tmp)) {
332 output->swap(tmp); 332 output->swap(tmp);
333 return true; 333 return true;
334 // We can try either the OS default charset or 'origin charset' here, 334 // We can try either the OS default charset or 'origin charset' here,
335 // As far as I can tell, IE does not support it. However, I've seen 335 // As far as I can tell, IE does not support it. However, I've seen
336 // web servers emit %-escaped string in a legacy encoding (usually 336 // web servers emit %-escaped string in a legacy encoding (usually
337 // origin charset). 337 // origin charset).
338 // TODO(jungshik) : Test IE further and consider adding a fallback here. 338 // TODO(jungshik) : Test IE further and consider adding a fallback here.
339 } 339 }
340 return false; 340 return false;
341 } 341 }
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 for (int i = 0; i < array_size; i++) { 907 for (int i = 0; i < array_size; i++) {
908 if (kAllowedFtpPorts[i] == port) { 908 if (kAllowedFtpPorts[i] == port) {
909 return true; 909 return true;
910 } 910 }
911 } 911 }
912 // Port not explicitly allowed by FTP, so return the default restrictions. 912 // Port not explicitly allowed by FTP, so return the default restrictions.
913 return IsPortAllowedByDefault(port); 913 return IsPortAllowedByDefault(port);
914 } 914 }
915 915
916 } // namespace net 916 } // namespace net
OLDNEW
« no previous file with comments | « base/string_util_unittest.cc ('k') | net/base/net_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698