summaryrefslogtreecommitdiffstats
path: root/jingle/notifier/listener
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 22:10:45 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 22:10:45 +0000
commitbbe1571f0e657d3ba18c05835f06c297b863cc09 (patch)
treef45ace7793d8883d50d2d57f543c2e80a57a07a0 /jingle/notifier/listener
parentc1a2b233574df6256681b1ed1f7a18a10d942d10 (diff)
downloadchromium_src-bbe1571f0e657d3ba18c05835f06c297b863cc09.zip
chromium_src-bbe1571f0e657d3ba18c05835f06c297b863cc09.tar.gz
chromium_src-bbe1571f0e657d3ba18c05835f06c297b863cc09.tar.bz2
Stop doing unnecessary UTF-8 to UTF-16 conversions in JSONWriter.
The JSONReader only accepts UTF-8 input strings and converts \uXXXX sequences back into UTF-8. However, the JSONWriter converts all non-ASCII characters to UTF-16 escape sequences. This round-tripping is sub-optimal, as noted in a TODO from r54359. One reason for this may be that JsonDoubleQuote(), used by JSONWriter, does not handle UTF-8 bytes correctly, interpreting them as code points and writing them out as \u00XX sequences. If this were read back through a RFC-compliant JSON parser, the result would be an invalid encoding error. JsonDoubleQuote() does handle UTF-16 correctly, though. This rewrites the base/json/string_escape.h API and fixes the above UTF-8 issue by dividing callers up into three groups: 1. Those that pass valid UTF-8 to be escaped. Prior to this change, very few callers used this variant. Those that did were likely using ASCII, otherwise the output would be mangled due to the above issue. Now, valid UTF-8 will be passed through to the output unescaped. Invalid UTF-8 sequences are replaced with U+FFFD. 2. Those that pass valid UTF-16 to be escaped. This function now validates that the input is valid UTF-16, and then converts it to unescaped UTF-8 sequences for the output. 3. Those that pass arbitrary byte arrays as std::string and expect a non-RFC- compliant encoding of the binary data using \uXXXX escapes. This behavior is now in the EscapeBytesAsInvalidJSONString() function. It is only used by callers who want a "debug string" but do not expect to actually parse the output as valid JSON, since it is not. Additionally, this removes the JSONWriter::OPTIONS_DO_NOT_ESCAPE flag, since the writer can now handle UTF-8 appropriately. BUG=15466 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=239800 Reverted: https://src.chromium.org/viewvc/chrome?view=rev&revision=240082 R=asanka@chromium.org, bauerb@chromium.org, mark@chromium.org, thakis@chromium.org, zea@chromium.org Review URL: https://codereview.chromium.org/100823007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240190 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle/notifier/listener')
-rw-r--r--jingle/notifier/listener/notification_defines.cc10
1 files changed, 6 insertions, 4 deletions
diff --git a/jingle/notifier/listener/notification_defines.cc b/jingle/notifier/listener/notification_defines.cc
index f4f3e40..f7c8f8f 100644
--- a/jingle/notifier/listener/notification_defines.cc
+++ b/jingle/notifier/listener/notification_defines.cc
@@ -65,10 +65,12 @@ bool Notification::Equals(const Notification& other) const {
}
std::string Notification::ToString() const {
- // |channel| or |data| could hold binary data, so use GetDoubleQuotedJson()
- // to escape them.
- const std::string& printable_channel = base::GetDoubleQuotedJson(channel);
- const std::string& printable_data = base::GetDoubleQuotedJson(data);
+ // |channel| or |data| could hold binary data, so convert all non-ASCII
+ // characters to escape sequences.
+ const std::string& printable_channel =
+ base::EscapeBytesAsInvalidJSONString(channel, true /* put_in_quotes */);
+ const std::string& printable_data =
+ base::EscapeBytesAsInvalidJSONString(data, true /* put_in_quotes */);
return
"{ channel: " + printable_channel + ", data: " + printable_data + " }";
}