diff options
author | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-14 17:45:26 +0000 |
---|---|---|
committer | tapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-14 17:45:26 +0000 |
commit | 9e63f95f6ca9261abc28b0cfb4a9a3ede672dfcd (patch) | |
tree | c6bbb2639a05280993f9cc3cd8fbb691208f36cd /base/json | |
parent | 536fd0b69edf4b73f057fe9c79f15beddd239ef8 (diff) | |
download | chromium_src-9e63f95f6ca9261abc28b0cfb4a9a3ede672dfcd.zip chromium_src-9e63f95f6ca9261abc28b0cfb4a9a3ede672dfcd.tar.gz chromium_src-9e63f95f6ca9261abc28b0cfb4a9a3ede672dfcd.tar.bz2 |
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
Diffstat (limited to 'base/json')
-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")); |