Commit c82e415c authored by yurys@chromium.org's avatar yurys@chromium.org

Make sure string passed to sendMessageToEmbedder is a valid unicode string

The message passed to the method is a result of JSON.stringify and may contain noncharacter unicode code points (http://www.unicode.org/faq/private_use.html#noncharacters). Since we know that the message is a JSON string we can use \uXXXX escape sequences for bad symbols. The function escapes not only noncharacters which produces valid output and allows to keep implementation simple.

BUG=347899
R=pfeldman@chromium.org

Review URL: https://codereview.chromium.org/178473027

git-svn-id: svn://svn.chromium.org/blink/trunk@168448 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 83edd12b
...@@ -160,16 +160,33 @@ void InspectorFrontendHost::copyText(const String& text) ...@@ -160,16 +160,33 @@ void InspectorFrontendHost::copyText(const String& text)
Pasteboard::generalPasteboard()->writePlainText(text, Pasteboard::CannotSmartReplace); Pasteboard::generalPasteboard()->writePlainText(text, Pasteboard::CannotSmartReplace);
} }
static String escapeUnicodeNonCharacters(const String& str)
{
StringBuilder dst;
for (unsigned i = 0; i < str.length(); ++i) {
UChar c = str[i];
if (c > 126) {
unsigned symbol = static_cast<unsigned>(c);
String symbolCode = String::format("\\u%04X", symbol);
dst.append(symbolCode);
} else {
dst.append(c);
}
}
return dst.toString();
}
void InspectorFrontendHost::sendMessageToBackend(const String& message) void InspectorFrontendHost::sendMessageToBackend(const String& message)
{ {
if (m_client) if (m_client)
m_client->sendMessageToBackend(message); m_client->sendMessageToBackend(escapeUnicodeNonCharacters(message));
} }
void InspectorFrontendHost::sendMessageToEmbedder(const String& message) void InspectorFrontendHost::sendMessageToEmbedder(const String& message)
{ {
if (m_client) if (m_client)
m_client->sendMessageToEmbedder(message); m_client->sendMessageToEmbedder(escapeUnicodeNonCharacters(message));
} }
void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMenuItem>& items) void InspectorFrontendHost::showContextMenu(Event* event, const Vector<ContextMenuItem>& items)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment