diff options
-rw-r--r-- | base/json_reader.cc | 12 | ||||
-rw-r--r-- | base/json_reader_unittest.cc | 18 |
2 files changed, 22 insertions, 8 deletions
diff --git a/base/json_reader.cc b/base/json_reader.cc index fd11a18..2c3ab0b 100644 --- a/base/json_reader.cc +++ b/base/json_reader.cc @@ -601,15 +601,11 @@ bool JSONReader::EatComment() { // Block comment, read until */ json_pos_ += 2; while ('\0' != *json_pos_) { - switch (*json_pos_) { - case '*': - if ('/' == *(json_pos_ + 1)) { - json_pos_ += 2; - return true; - } - default: - ++json_pos_; + if ('*' == *json_pos_ && '/' == *(json_pos_ + 1)) { + json_pos_ += 2; + return true; } + ++json_pos_; } } else { return false; diff --git a/base/json_reader_unittest.cc b/base/json_reader_unittest.cc index 0513eb5..be3e07e 100644 --- a/base/json_reader_unittest.cc +++ b/base/json_reader_unittest.cc @@ -24,6 +24,24 @@ TEST(JSONReaderTest, Reading) { ASSERT_TRUE(root.get()); ASSERT_TRUE(root->IsType(Value::TYPE_BOOLEAN)); + // Embedded comment + root.reset(JSONReader().JsonToValue("/* comment */null", false, false)); + ASSERT_TRUE(root.get()); + ASSERT_TRUE(root->IsType(Value::TYPE_NULL)); + root.reset(JSONReader().JsonToValue("40 /* comment */", false, false)); + ASSERT_TRUE(root.get()); + ASSERT_TRUE(root->IsType(Value::TYPE_INTEGER)); + root.reset(JSONReader().JsonToValue("true // comment", false, false)); + ASSERT_TRUE(root.get()); + ASSERT_TRUE(root->IsType(Value::TYPE_BOOLEAN)); + root.reset(JSONReader().JsonToValue("/* comment */\"sample string\"", + false, false)); + ASSERT_TRUE(root.get()); + ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); + std::string value; + ASSERT_TRUE(root->GetAsString(&value)); + ASSERT_EQ("sample string", value); + // Test number formats root.reset(JSONReader().JsonToValue("43", false, false)); ASSERT_TRUE(root.get()); |