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

Unified Diff: base/json/json_parser.cc

Issue 2475583002: Adds option for JSON reader to allow invalid utf characters (Closed)
Patch Set: replace Created 4 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 | « base/json/json_parser.h ('k') | base/json/json_parser_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/json_parser.cc
diff --git a/base/json/json_parser.cc b/base/json/json_parser.cc
index 9ce6a2c1e73fa7105402ee84580eb564bcddd700..9bea83fcd1e9c65b0655f3feb1dd4aad41d83ab3 100644
--- a/base/json/json_parser.cc
+++ b/base/json/json_parser.cc
@@ -188,6 +188,8 @@ class StackMarker {
} // namespace
+const char kUnicodeReplacementString[] = "\xFF\xDF";
brettw 2016/11/08 19:21:19 I'm not sure where you got this string. U+FFFD in
brettw 2016/11/08 20:26:56 (add x's in there after the backslashes)
sky 2016/11/08 23:55:35 Done.
+
JSONParser::JSONParser(int options)
: options_(options),
start_pos_(nullptr),
@@ -629,8 +631,13 @@ bool JSONParser::ConsumeStringRaw(StringBuilder* out) {
pos_ = start_pos_ + index_; // CBU8_NEXT is postcrement.
CBU8_NEXT(start_pos_, index_, length, next_char);
if (next_char < 0 || !IsValidCharacter(next_char)) {
- ReportError(JSONReader::JSON_UNSUPPORTED_ENCODING, 1);
- return false;
+ if ((options_ & JSON_REPLACE_INVALID_CHARACTERS) == 0) {
+ ReportError(JSONReader::JSON_UNSUPPORTED_ENCODING, 1);
+ return false;
+ }
+ string.Convert();
+ string.AppendString(kUnicodeReplacementString);
+ continue;
}
if (next_char == '"') {
« no previous file with comments | « base/json/json_parser.h ('k') | base/json/json_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698