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

Side by Side Diff: base/json/json_reader_unittest.cc

Issue 2823023002: Do not silently drop \u0000 in base::JSONReader (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « base/json/json_parser.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 ASSERT_TRUE(root); 233 ASSERT_TRUE(root);
234 EXPECT_TRUE(root->IsType(Value::Type::STRING)); 234 EXPECT_TRUE(root->IsType(Value::Type::STRING));
235 std::string str_val; 235 std::string str_val;
236 EXPECT_TRUE(root->GetAsString(&str_val)); 236 EXPECT_TRUE(root->GetAsString(&str_val));
237 EXPECT_EQ(" \"\\/\b\f\n\r\t\v", str_val); 237 EXPECT_EQ(" \"\\/\b\f\n\r\t\v", str_val);
238 } 238 }
239 239
240 { 240 {
241 // Test hex and unicode escapes including the null character. 241 // Test hex and unicode escapes including the null character.
242 std::unique_ptr<Value> root = 242 std::unique_ptr<Value> root =
243 JSONReader().ReadToValue("\"\\x41\\x00\\u1234\""); 243 JSONReader().ReadToValue("\"\\x41\\x00\\u1234\\u0000\"");
244 ASSERT_TRUE(root); 244 ASSERT_TRUE(root);
245 EXPECT_TRUE(root->IsType(Value::Type::STRING)); 245 EXPECT_TRUE(root->IsType(Value::Type::STRING));
246 std::string str_val; 246 std::string str_val;
247 EXPECT_TRUE(root->GetAsString(&str_val)); 247 EXPECT_TRUE(root->GetAsString(&str_val));
248 EXPECT_EQ(std::wstring(L"A\0\x1234", 3), UTF8ToWide(str_val)); 248 EXPECT_EQ(std::wstring(L"A\0\x1234\0", 4), UTF8ToWide(str_val));
249 } 249 }
250 250
251 { 251 {
252 // Test invalid strings 252 // Test invalid strings
253 EXPECT_FALSE(JSONReader().ReadToValue("\"no closing quote")); 253 EXPECT_FALSE(JSONReader().ReadToValue("\"no closing quote"));
254 EXPECT_FALSE(JSONReader().ReadToValue("\"\\z invalid escape char\"")); 254 EXPECT_FALSE(JSONReader().ReadToValue("\"\\z invalid escape char\""));
255 EXPECT_FALSE(JSONReader().ReadToValue("\"\\xAQ invalid hex code\"")); 255 EXPECT_FALSE(JSONReader().ReadToValue("\"\\xAQ invalid hex code\""));
256 EXPECT_FALSE(JSONReader().ReadToValue("not enough hex chars\\x1\"")); 256 EXPECT_FALSE(JSONReader().ReadToValue("not enough hex chars\\x1\""));
257 EXPECT_FALSE(JSONReader().ReadToValue("\"not enough escape chars\\u123\"")); 257 EXPECT_FALSE(JSONReader().ReadToValue("\"not enough escape chars\\u123\""));
258 EXPECT_FALSE( 258 EXPECT_FALSE(
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 669
670 TEST(JSONReaderTest, IllegalTrailingNull) { 670 TEST(JSONReaderTest, IllegalTrailingNull) {
671 const char json[] = { '"', 'n', 'u', 'l', 'l', '"', '\0' }; 671 const char json[] = { '"', 'n', 'u', 'l', 'l', '"', '\0' };
672 std::string json_string(json, sizeof(json)); 672 std::string json_string(json, sizeof(json));
673 JSONReader reader; 673 JSONReader reader;
674 EXPECT_FALSE(reader.ReadToValue(json_string)); 674 EXPECT_FALSE(reader.ReadToValue(json_string));
675 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, reader.error_code()); 675 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, reader.error_code());
676 } 676 }
677 677
678 } // namespace base 678 } // namespace base
OLDNEW
« no previous file with comments | « base/json/json_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698