Commit 23d878af authored by Maks Orlovich's avatar Maks Orlovich Committed by Chromium LUCI CQ

Fix encoding handling on decode of inspector state 8-bit strings

The marshalling code writes out utf-8, but demarshalling used WTFString
ctor which is latin1

Bug: 1161142
Change-Id: I55c4f5a38d76ff6f6c6e502e6a84471327de37d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602360
Commit-Queue: Maksim Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841510}
parent 0b1539fc
......@@ -128,7 +128,7 @@ void InspectorAgentState::Serialize(const WTF::String& v,
bool InspectorAgentState::Deserialize(span<uint8_t> in, WTF::String* v) {
CBORTokenizer tokenizer(in);
if (tokenizer.TokenTag() == CBORTokenTag::STRING8) {
*v = WTF::String(
*v = WTF::String::FromUTF8(
reinterpret_cast<const char*>(tokenizer.GetString8().data()),
static_cast<size_t>(tokenizer.GetString8().size()));
return true;
......
......@@ -82,10 +82,14 @@ TEST(InspectorSessionStateTest, SimpleFields) {
simple_agent.counter_.Set(311);
simple_agent.bytes_.Set({0xde, 0xad, 0xbe, 0xef});
// Test that Latin1 is handled properly
simple_agent.message_.Set("\xC7 cedilla");
EXPECT_EQ(true, simple_agent.enabled_.Get());
EXPECT_EQ(11.0, simple_agent.field1_.Get());
EXPECT_EQ(42.0, simple_agent.multiplier_.Get());
EXPECT_EQ(311, simple_agent.counter_.Get());
EXPECT_EQ("\xC7 cedilla", simple_agent.message_.Get());
EXPECT_THAT(simple_agent.bytes_.Get(), ElementsAre(0xde, 0xad, 0xbe, 0xef));
// Now send the updates back to the browser session.
......@@ -101,6 +105,7 @@ TEST(InspectorSessionStateTest, SimpleFields) {
EXPECT_EQ(11.0, simple_agent.field1_.Get());
EXPECT_EQ(42.0, simple_agent.multiplier_.Get());
EXPECT_EQ(311, simple_agent.counter_.Get());
EXPECT_EQ("\xC7 cedilla", simple_agent.message_.Get());
EXPECT_THAT(simple_agent.bytes_.Get(), ElementsAre(0xde, 0xad, 0xbe, 0xef));
simple_agent.enabled_.Set(false);
......
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