diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/json/json_parser.cc | 7 | ||||
-rw-r--r-- | base/json/json_reader_unittest.cc | 13 |
2 files changed, 18 insertions, 2 deletions
diff --git a/base/json/json_parser.cc b/base/json/json_parser.cc index 8442b01..cc669f4 100644 --- a/base/json/json_parser.cc +++ b/base/json/json_parser.cc @@ -435,15 +435,18 @@ bool JSONParser::EatComment() { return true; } } else if (next_char == '*') { + char previous_char = '\0'; // Block comment, read until end marker. - while (CanConsume(2)) { - if (*NextChar() == '*' && *NextChar() == '/') { + while (CanConsume(1)) { + next_char = *NextChar(); + if (previous_char == '*' && next_char == '/') { // EatWhitespaceAndComments will inspect pos_, which will still be on // the last / of the comment, so advance once more (which may also be // end of input). NextChar(); return true; } + previous_char = next_char; } // If the comment is unterminated, GetNextToken will report T_END_OF_INPUT. diff --git a/base/json/json_reader_unittest.cc b/base/json/json_reader_unittest.cc index 38bf590..353e095 100644 --- a/base/json/json_reader_unittest.cc +++ b/base/json/json_reader_unittest.cc @@ -62,6 +62,19 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(root.get()); list = static_cast<ListValue*>(root.get()); EXPECT_EQ(3u, list->GetSize()); + root.reset(JSONReader().ReadToValue("/* comment **/42")); + ASSERT_TRUE(root.get()); + EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER)); + EXPECT_TRUE(root->GetAsInteger(&int_val)); + EXPECT_EQ(42, int_val); + root.reset(JSONReader().ReadToValue( + "/* comment **/\n" + "// */ 43\n" + "44")); + ASSERT_TRUE(root.get()); + EXPECT_TRUE(root->IsType(Value::TYPE_INTEGER)); + EXPECT_TRUE(root->GetAsInteger(&int_val)); + EXPECT_EQ(44, int_val); // Test number formats root.reset(JSONReader().ReadToValue("43")); |