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

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

Issue 12476030: Handle block comments ending in **/ in the JSON parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: neater fix Created 7 years, 9 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 "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 EXPECT_EQ(2u, list->GetSize()); 55 EXPECT_EQ(2u, list->GetSize());
56 int int_val = 0; 56 int int_val = 0;
57 EXPECT_TRUE(list->GetInteger(0, &int_val)); 57 EXPECT_TRUE(list->GetInteger(0, &int_val));
58 EXPECT_EQ(1, int_val); 58 EXPECT_EQ(1, int_val);
59 EXPECT_TRUE(list->GetInteger(1, &int_val)); 59 EXPECT_TRUE(list->GetInteger(1, &int_val));
60 EXPECT_EQ(3, int_val); 60 EXPECT_EQ(3, int_val);
61 root.reset(JSONReader().ReadToValue("[1, /*a*/2, 3]")); 61 root.reset(JSONReader().ReadToValue("[1, /*a*/2, 3]"));
62 ASSERT_TRUE(root.get()); 62 ASSERT_TRUE(root.get());
63 list = static_cast<ListValue*>(root.get()); 63 list = static_cast<ListValue*>(root.get());
64 EXPECT_EQ(3u, list->GetSize()); 64 EXPECT_EQ(3u, list->GetSize());
65 root.reset(JSONReader().ReadToValue("/* comment **/42"));
66 ASSERT_TRUE(root.get());
67 EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER));
68 EXPECT_TRUE(root->GetAsInteger(&int_val));
69 EXPECT_EQ(42, int_val);
70 root.reset(JSONReader().ReadToValue(
71 "/* comment **/\n"
72 "// */ 43\n"
73 "44"));
74 ASSERT_TRUE(root.get());
75 EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER));
76 EXPECT_TRUE(root->GetAsInteger(&int_val));
77 EXPECT_EQ(44, int_val);
65 78
66 // Test number formats 79 // Test number formats
67 root.reset(JSONReader().ReadToValue("43")); 80 root.reset(JSONReader().ReadToValue("43"));
68 ASSERT_TRUE(root.get()); 81 ASSERT_TRUE(root.get());
69 EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER)); 82 EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER));
70 EXPECT_TRUE(root->GetAsInteger(&int_val)); 83 EXPECT_TRUE(root->GetAsInteger(&int_val));
71 EXPECT_EQ(43, int_val); 84 EXPECT_EQ(43, int_val);
72 85
73 // According to RFC4627, oct, hex, and leading zeros are invalid JSON. 86 // According to RFC4627, oct, hex, and leading zeros are invalid JSON.
74 root.reset(JSONReader().ReadToValue("043")); 87 root.reset(JSONReader().ReadToValue("043"));
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 652
640 TEST(JSONReaderTest, IllegalTrailingNull) { 653 TEST(JSONReaderTest, IllegalTrailingNull) {
641 const char json[] = { '"', 'n', 'u', 'l', 'l', '"', '\0' }; 654 const char json[] = { '"', 'n', 'u', 'l', 'l', '"', '\0' };
642 std::string json_string(json, sizeof(json)); 655 std::string json_string(json, sizeof(json));
643 JSONReader reader; 656 JSONReader reader;
644 EXPECT_FALSE(reader.ReadToValue(json_string)); 657 EXPECT_FALSE(reader.ReadToValue(json_string));
645 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, reader.error_code()); 658 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, reader.error_code());
646 } 659 }
647 660
648 } // namespace base 661 } // 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