Index: base/json/json_parser.cc |
diff --git a/base/json/json_parser.cc b/base/json/json_parser.cc |
index 9ce6a2c1e73fa7105402ee84580eb564bcddd700..cd427da9ea2537fa86c103452d72505731ab6129 100644 |
--- a/base/json/json_parser.cc |
+++ b/base/json/json_parser.cc |
@@ -188,6 +188,9 @@ class StackMarker { |
} // namespace |
+// This is U+FFFD. |
+const char kUnicodeReplacementString[] = "\xEF\xBF\xBD"; |
+ |
JSONParser::JSONParser(int options) |
: options_(options), |
start_pos_(nullptr), |
@@ -626,11 +629,18 @@ bool JSONParser::ConsumeStringRaw(StringBuilder* out) { |
int32_t next_char = 0; |
while (CanConsume(1)) { |
+ int start_index = index_; |
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; |
+ } |
+ CBU8_NEXT(start_pos_, start_index, length, next_char); |
+ string.Convert(); |
+ string.AppendString(kUnicodeReplacementString); |
+ continue; |
} |
if (next_char == '"') { |