Commit c9ab2e4e authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol

New Rev: 201330a4e7a527dfc6d73bbb3c297562edcf28f8

Change-Id: I8d47c1944a43d1ea96cd572a1ff41ea378ba255b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2017676
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734700}
parent 1d126b4a
......@@ -85,4 +85,5 @@ Tests TestRunner.RuntimeAgent.evaluate can handle invalid Unicode code points an
"'􏿿' === '\u{10FFFF}'" -> true
"'􏿿'.codePointAt(0).toString(16)" -> 10ffff
"String.fromCodePoint(0x10FFFF)" -> 􏿿
"String.fromCodePoint(0xFFFF)" -> ￿
......@@ -127,6 +127,14 @@
await test("'\u{10FFFF}'.codePointAt(0).toString(16)");
await test("String.fromCodePoint(0x10FFFF)");
// Constructs a string with the Unicode code point 0xffff in V8.
// On the way back to the browser, it will eventually get
// converted to JSON, e.g. by escaping the character into
// \uffff for transport. Eventually, as reflected in the
// test expectation file, it's converted into a 3 byte UTF8
// sequence for that codepoint, that is 0xef 0xbf 0xbf.
await test("String.fromCodePoint(0xFFFF)");
}
TestRunner.completeTest();
......
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 6361d066985aafcb5c7d7b4066da0a0ecaa5866d
Revision: 201330a4e7a527dfc6d73bbb3c297562edcf28f8
License: BSD
License File: LICENSE
Security Critical: yes
......
......@@ -225,14 +225,17 @@ class JSONEncoder : public ParserHandler {
// belonging to this Unicode character into |codepoint|.
if (ii + num_bytes_left >= chars.size())
continue;
bool invalid_byte_seen = false;
while (num_bytes_left > 0) {
c = chars[++ii];
--num_bytes_left;
// Check the next byte is a continuation byte, that is 10xx xxxx.
if ((c & 0xc0) != 0x80)
continue;
invalid_byte_seen = true;
codepoint = (codepoint << 6) | (c & 0x3f);
}
if (invalid_byte_seen)
continue;
// Disallow overlong encodings for ascii characters, as these
// would include " and other characters significant to JSON
......@@ -246,7 +249,7 @@ class JSONEncoder : public ParserHandler {
// So, now we transcode to UTF16,
// using the math described at https://en.wikipedia.org/wiki/UTF-16,
// for either one or two 16 bit characters.
if (codepoint < 0xffff) {
if (codepoint <= 0xffff) {
Emit("\\u");
PrintHex(static_cast<uint16_t>(codepoint), out_);
continue;
......
......@@ -49,6 +49,49 @@ TEST(JsonEncoder, OverlongEncodings) {
EXPECT_EQ("\"\"", out); // Empty string means that 0x7f was rejected (good).
}
TEST(JsonEncoder, NotAContinuationByte) {
std::string out;
Status status;
std::unique_ptr<ParserHandler> writer = NewJSONEncoder(&out, &status);
// |world| encodes the globe as a 4 byte UTF8 sequence. So, naturally, it'll
// have a start byte, followed by three continuation bytes.
std::string world = "🌎";
ASSERT_EQ(4u, world.size());
ASSERT_EQ(world[1] & 0xc0, 0x80); // checks for continuation byte
ASSERT_EQ(world[2] & 0xc0, 0x80);
ASSERT_EQ(world[3] & 0xc0, 0x80);
// Now create a corrupted UTF8 string, starting with the first two bytes from
// |world|, followed by an ASCII message. Upon encountering '!', our decoder
// will realize that it's not a continuation byte; it'll skip to the end of
// this UTF8 sequence and continue with the next character. In this case, the
// 'H', of "Hello".
std::vector<uint8_t> chars;
chars.push_back(world[0]);
chars.push_back(world[1]);
chars.push_back('!');
chars.push_back('?');
chars.push_back('H');
chars.push_back('e');
chars.push_back('l');
chars.push_back('l');
chars.push_back('o');
writer->HandleString8(SpanFrom(chars));
EXPECT_EQ("\"Hello\"", out); // "Hello" shows we restarted at 'H'.
}
TEST(JsonEncoder, EscapesFFFF) {
// This tests that the JSON encoder will escape the UTF16 input 0xffff as
// \uffff; useful to check this since it's an edge case.
std::vector<uint16_t> chars = {'a', 'b', 'c', 0xffff, 'd'};
std::string out;
Status status;
std::unique_ptr<ParserHandler> writer = NewJSONEncoder(&out, &status);
writer->HandleString16(span<uint16_t>(chars.data(), chars.size()));
EXPECT_EQ("\"abc\\uffffd\"", out);
}
TEST(JsonEncoder, IncompleteUtf8Sequence) {
std::string out;
Status status;
......
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