Add JSON-specific escaping, which has different rules from JS escaping.BUG=http://crbug.com/11431TEST=base_unittests.exe --gtest_filter=StringEscapeTest.Json*
Review URL: http://codereview.chromium.org/113606
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16485 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/json_writer.cc b/base/json_writer.cc
index aa66306c..a95798eb 100644
--- a/base/json_writer.cc
+++ b/base/json_writer.cc
@@ -92,16 +92,15 @@
case Value::TYPE_STRING:
{
+ std::string value;
+ bool result = node->GetAsString(&value);
+ DCHECK(result);
if (escape) {
- std::wstring value;
- bool result = node->GetAsString(&value);
- DCHECK(result);
- AppendQuotedString(value);
+ string_escape::JsonDoubleQuote(UTF8ToUTF16(value),
+ true,
+ json_string_);
} else {
- std::string value;
- bool result = node->GetAsString(&value);
- DCHECK(result);
- string_escape::JavascriptDoubleQuote(value, true, json_string_);
+ string_escape::JsonDoubleQuote(value, true, json_string_);
}
break;
}
@@ -182,9 +181,9 @@
}
void JSONWriter::AppendQuotedString(const std::wstring& str) {
- string_escape::JavascriptDoubleQuote(WideToUTF16Hack(str),
- true,
- json_string_);
+ string_escape::JsonDoubleQuote(WideToUTF16Hack(str),
+ true,
+ json_string_);
}
void JSONWriter::IndentLine(int depth) {