Commit 6d58017c authored by Shu Chen's avatar Shu Chen Committed by Commit Bot

The response JSON string should be escaped.

Bug: 906511
Change-Id: Ia8a1cd0ef0fabb9dfc3777f0758cd4470f75ac3f
Reviewed-on: https://chromium-review.googlesource.com/c/1343461Reviewed-by: default avatarLeo Zhang <googleo@chromium.org>
Commit-Queue: Shu Chen <shuchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609583}
parent f4e578ae
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chromeos/services/ime/input_engine.h" #include "chromeos/services/ime/input_engine.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/json/string_escape.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -152,8 +153,10 @@ std::string InputEngine::Process(const std::string& message, ...@@ -152,8 +153,10 @@ std::string InputEngine::Process(const std::string& message,
response_str += (res.key_handled ? "true" : "false"); response_str += (res.key_handled ? "true" : "false");
std::vector<std::string> ops; std::vector<std::string> ops;
if (!res.commit_text.empty()) { if (!res.commit_text.empty()) {
ops.push_back("{\"method\":\"commitText\",\"arguments\":[\"" + std::string commit_text;
res.commit_text + "\"]}"); base::EscapeJSONString(res.commit_text, false, &commit_text);
ops.push_back("{\"method\":\"commitText\",\"arguments\":[\"" + commit_text +
"\"]}");
} }
// Need to add the setComposition operation to the result when the key is // Need to add the setComposition operation to the result when the key is
// handled and commit_text and composition_text are both empty. // handled and commit_text and composition_text are both empty.
...@@ -161,8 +164,10 @@ std::string InputEngine::Process(const std::string& message, ...@@ -161,8 +164,10 @@ std::string InputEngine::Process(const std::string& message,
// composition. // composition.
if (!res.composition_text.empty() || if (!res.composition_text.empty() ||
(res.key_handled && res.commit_text.empty())) { (res.key_handled && res.commit_text.empty())) {
std::string composition_text;
base::EscapeJSONString(res.composition_text, false, &composition_text);
ops.push_back("{\"method\":\"setComposition\",\"arguments\":[\"" + ops.push_back("{\"method\":\"setComposition\",\"arguments\":[\"" +
res.composition_text + "\"]}"); composition_text + "\"]}");
} }
if (ops.empty()) { if (ops.empty()) {
response_str += "}"; response_str += "}";
......
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