From d46d6f3b80099ce0c630185a2e86b649bba49254 Mon Sep 17 00:00:00 2001 From: "sky@google.com" Date: Wed, 1 Oct 2008 17:26:06 +0000 Subject: Fixes bug where JSON reader errored on reading vertical tabs (\v). The writer properly escapes a vertical tab, but the readed instead errored on the vertical this. This resulted in lost bookmarks:( BUG=3031 TEST=covered by unit tests Review URL: http://codereview.chromium.org/5628 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2759 0039d316-1c4b-4281-b951-d872f2087c98 --- base/json_reader.cc | 4 ++++ base/json_reader_unittest.cc | 4 ++-- base/string_escape.cc | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/base/json_reader.cc b/base/json_reader.cc index 8d0cab4..c0e019b 100644 --- a/base/json_reader.cc +++ b/base/json_reader.cc @@ -361,6 +361,7 @@ JSONReader::Token JSONReader::ParseStringToken() { case 'n': case 'r': case 't': + case 'v': case '"': break; default: @@ -406,6 +407,9 @@ bool JSONReader::DecodeString(const Token& token, Value** node) { case 't': decoded_str.push_back('\t'); break; + case 'v': + decoded_str.push_back('\v'); + break; case 'x': decoded_str.push_back((HexToInt(*(token.begin + i + 1)) << 4) + diff --git a/base/json_reader_unittest.cc b/base/json_reader_unittest.cc index c2d6a42..4339be1 100644 --- a/base/json_reader_unittest.cc +++ b/base/json_reader_unittest.cc @@ -214,13 +214,13 @@ TEST(JSONReaderTest, Reading) { // Test basic string escapes root = NULL; - ASSERT_TRUE(JSONReader::JsonToValue("\" \\\"\\\\\\/\\b\\f\\n\\r\\t\"", &root, + ASSERT_TRUE(JSONReader::JsonToValue("\" \\\"\\\\\\/\\b\\f\\n\\r\\t\\v\"", &root, false, false)); ASSERT_TRUE(root); ASSERT_TRUE(root->IsType(Value::TYPE_STRING)); str_val.clear(); ASSERT_TRUE(root->GetAsString(&str_val)); - ASSERT_EQ(L" \"\\/\b\f\n\r\t", str_val); + ASSERT_EQ(L" \"\\/\b\f\n\r\t\v", str_val); delete root; // Test hex and unicode escapes including the null character. diff --git a/base/string_escape.cc b/base/string_escape.cc index 5b85e9c..c2fc542 100644 --- a/base/string_escape.cc +++ b/base/string_escape.cc @@ -14,6 +14,7 @@ namespace string_escape { // returns true and appends the escape sequence to |dst|. template static bool JavascriptSingleEscapeChar(const CHAR c, std::string* dst) { + // WARNING: if you add a new case here, you need to update the reader as well. switch (c) { case '\b': dst->append("\\b"); -- cgit v1.1