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

Unified Diff: base/json/json_parser_unittest.cc

Issue 2475583002: Adds option for JSON reader to allow invalid utf characters (Closed)
Patch Set: comment 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.cc ('k') | base/json/json_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/json_parser_unittest.cc
diff --git a/base/json/json_parser_unittest.cc b/base/json/json_parser_unittest.cc
index eacd1024993ce5d1924fde1273bbba317345434d..6023288925f4a1bb5da5da529c34dffff5225e47 100644
--- a/base/json/json_parser_unittest.cc
+++ b/base/json/json_parser_unittest.cc
@@ -17,8 +17,9 @@ namespace internal {
class JSONParserTest : public testing::Test {
public:
- JSONParser* NewTestParser(const std::string& input) {
- JSONParser* parser = new JSONParser(JSON_PARSE_RFC);
+ JSONParser* NewTestParser(const std::string& input,
+ int options = JSON_PARSE_RFC) {
+ JSONParser* parser = new JSONParser(options);
parser->start_pos_ = input.data();
parser->pos_ = parser->start_pos_;
parser->end_pos_ = parser->start_pos_ + input.length();
@@ -328,5 +329,18 @@ TEST_F(JSONParserTest, DecodeNegativeEscapeSequence) {
EXPECT_FALSE(JSONReader::Read("[\"\\u-00A\"]"));
}
+// Verifies invalid utf-8 characters are replaced.
+TEST_F(JSONParserTest, ReplaceInvalidCharacters) {
+ const std::string bogus_char = "󿿿";
+ const std::string quoted_bogus_char = "\"" + bogus_char + "\"";
+ std::unique_ptr<JSONParser> parser(
+ NewTestParser(quoted_bogus_char, JSON_REPLACE_INVALID_CHARACTERS));
+ std::unique_ptr<Value> value(parser->ConsumeString());
+ ASSERT_TRUE(value.get());
+ std::string str;
+ EXPECT_TRUE(value->GetAsString(&str));
+ EXPECT_EQ(kUnicodeReplacementString, str);
+}
+
} // namespace internal
} // namespace base
« no previous file with comments | « base/json/json_parser.cc ('k') | base/json/json_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698