Commit 4457fd96 authored by David Black's avatar David Black Committed by Commit Bot

Unescape html entities in Assistant before display.

HTTP headers from proactive suggestion responses may be unescaped. These
strings can be shown in both the proactive suggestions UI as well as in
Assistant UI. We need to unescape these strings before displaying them
to the user.

Bug: b:140645078
Change-Id: I967c85a67e230bb86f029f517147b4b1b1fbd3ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790479Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#695233}
parent 234580e5
......@@ -13,6 +13,7 @@ include_rules = [
"+chromeos/assistant",
"+chromeos/services/assistant/public",
"+mojo/public/cpp",
"+net/base",
"+services/content/public",
"+third_party/skia/include/core",
"+ui",
......
......@@ -10,6 +10,7 @@
#include "ash/assistant/model/assistant_query.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "base/strings/utf_string_conversions.h"
#include "net/base/escape.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/layout/box_layout.h"
......@@ -109,11 +110,14 @@ void AssistantQueryView::SetText(const std::string& high_confidence_text,
if (high_confidence_text.empty() && low_confidence_text.empty()) {
label_->SetText(base::string16());
} else {
// When coming from the server, both |high_confidence_text| and
// |low_confidence_text| may be HTML escaped, so we need to unescape both
// before displaying to avoid printing HTML entities to the user.
const base::string16& high_confidence_text_16 =
base::UTF8ToUTF16(high_confidence_text);
net::UnescapeForHTML(base::UTF8ToUTF16(high_confidence_text));
const base::string16& low_confidence_text_16 =
base::UTF8ToUTF16(low_confidence_text);
net::UnescapeForHTML(base::UTF8ToUTF16(low_confidence_text));
label_->SetText(high_confidence_text_16 + low_confidence_text_16);
......
......@@ -11,6 +11,7 @@
#include "ash/public/cpp/assistant/proactive_suggestions.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "base/strings/utf_string_conversions.h"
#include "net/base/escape.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
......@@ -153,9 +154,15 @@ void ProactiveSuggestionsView::InitLayout() {
label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
label->SetLineHeight(kLineHeightDip);
label->SetMultiLine(false);
label->SetText(base::UTF8ToUTF16(delegate_->GetSuggestionsModel()
->GetProactiveSuggestions()
->description()));
// The |description| string coming from the proactive suggestions server may
// be HTML escaped so we need to unescape before displaying to avoid printing
// HTML entities to the user.
label->SetText(
net::UnescapeForHTML(base::UTF8ToUTF16(delegate_->GetSuggestionsModel()
->GetProactiveSuggestions()
->description())));
AddChildView(label);
// We impose a maximum width restriction on the proactive suggestions view.
......
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