Handle block comments ending in **/ in the JSON parser

BUG=177585
TEST=Covered by base_unittests --gtest_filter=JSONReaderTest.Reading


Review URL: https://chromiumcodereview.appspot.com/12476030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188120 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 9e63f95f6ca9261abc28b0cfb4a9a3ede672dfcd
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 @@
         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 @@
   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"));