Commit 6c224c4f authored by Becca Hughes's avatar Becca Hughes Committed by Commit Bot

Fix for Media Feeds crash when there are emojis

We should change the string conversion from UTF8
instead of ASCII.

BUG=1119506

Change-Id: I202e36568125c6a52d99db60e4101130421833f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363843
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Auto-Submit: Becca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800274}
parent 53c5a84a
......@@ -319,8 +319,11 @@ IN_PROC_BROWSER_TEST_F(MediaFeedsBrowserTest, DiscoverAndFetch) {
{
mojom::MediaFeedItemPtr expected_item = mojom::MediaFeedItem::New();
expected_item->id = 1;
expected_item->name =
base::ASCIIToUTF16("Anatomy of a Web Media Experience");
const std::string name = "Anatomy of a Web Media Experience 😊";
ASSERT_TRUE(
base::UTF8ToUTF16(name.c_str(), name.size(), &expected_item->name));
expected_item->type = mojom::MediaFeedItemType::kVideo;
expected_item->author = mojom::Author::New();
expected_item->author->name = "Google Chrome Developers";
......
......@@ -1076,7 +1076,12 @@ bool MediaFeedsConverter::GetMediaFeedItem(
auto* name = GetProperty(item.get(), schema_org::property::kName);
if (name && IsNonEmptyString(*name)) {
converted_item->name = base::ASCIIToUTF16(name->values->string_values[0]);
const auto value = name->values->string_values[0];
if (!base::UTF8ToUTF16(value.c_str(), value.size(),
&converted_item->name)) {
Log("Invalid name.");
return false;
}
} else {
Log("Invalid name.");
return false;
......@@ -1252,10 +1257,7 @@ void MediaFeedsConverter::GetDataFeedItems(
if (!GetMediaFeedItem(embedded_item->values->entity_values[0],
converted_item.get(), &item_ids,
/*is_embedded_item=*/true)) {
std::string item_name = !converted_item->name.empty()
? base::UTF16ToASCII(converted_item->name)
: "Unknown item";
Log("Item was invalid: " + item_name);
Log("Item was invalid");
continue;
}
......@@ -1281,10 +1283,7 @@ void MediaFeedsConverter::GetDataFeedItems(
} else {
if (!GetMediaFeedItem(item, converted_item.get(), &item_ids,
/*is_embedded_item=*/false)) {
std::string item_name = !converted_item->name.empty()
? base::UTF16ToASCII(converted_item->name)
: "Unknown item";
Log("Item was invalid: " + item_name);
Log("Item was invalid");
continue;
}
}
......
......@@ -31,7 +31,7 @@
"userInteractionCount": "4"
}
],
"name": "Anatomy of a Web Media Experience",
"name": "Anatomy of a Web Media Experience 😊",
"potentialAction": {
"@type": "WatchAction",
"target": "https://www.youtube.com/watch?v=lXm6jOQLe1Y"
......
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