Commit 5c2a3b92 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

XML Parser: &, <, and <⃒ should work.

They caused parsing errors because strings produced by them were not
escaped.

This CL fixes 27 failures in WPT.

Bug: 351767
Change-Id: I6ac10572cf63b0e8cdc6cd357631257a6a470be6
Reviewed-on: https://chromium-review.googlesource.com/936983Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539075}
parent 3e41336b
...@@ -1356,13 +1356,46 @@ static xmlEntityPtr GetXHTMLEntity(const xmlChar* name) { ...@@ -1356,13 +1356,46 @@ static xmlEntityPtr GetXHTMLEntity(const xmlChar* name) {
if (!number_of_code_units) if (!number_of_code_units)
return nullptr; return nullptr;
DCHECK_LE(number_of_code_units, 4u); constexpr size_t kSharedXhtmlEntityResultLength =
size_t entity_length_in_utf8 = ConvertUTF16EntityToUTF8( arraysize(g_shared_xhtml_entity_result);
utf16_decoded_entity, number_of_code_units, size_t entity_length_in_utf8;
reinterpret_cast<char*>(g_shared_xhtml_entity_result), // Unlike HTML parser, XML parser parses the content of named
WTF_ARRAY_LENGTH(g_shared_xhtml_entity_result)); // entities. So we need to escape '&' and '<'.
if (!entity_length_in_utf8) if (number_of_code_units == 1 && utf16_decoded_entity[0] == '&') {
return nullptr; g_shared_xhtml_entity_result[0] = '&';
g_shared_xhtml_entity_result[1] = '#';
g_shared_xhtml_entity_result[2] = '3';
g_shared_xhtml_entity_result[3] = '8';
g_shared_xhtml_entity_result[4] = ';';
entity_length_in_utf8 = 5;
} else if (number_of_code_units == 1 && utf16_decoded_entity[0] == '<') {
g_shared_xhtml_entity_result[0] = '&';
g_shared_xhtml_entity_result[1] = '#';
g_shared_xhtml_entity_result[2] = '6';
g_shared_xhtml_entity_result[3] = '0';
g_shared_xhtml_entity_result[4] = ';';
entity_length_in_utf8 = 5;
} else if (number_of_code_units == 2 && utf16_decoded_entity[0] == '<' &&
utf16_decoded_entity[1] == 0x20D2) {
g_shared_xhtml_entity_result[0] = '&';
g_shared_xhtml_entity_result[1] = '#';
g_shared_xhtml_entity_result[2] = '6';
g_shared_xhtml_entity_result[3] = '0';
g_shared_xhtml_entity_result[4] = ';';
g_shared_xhtml_entity_result[5] = 0xE2;
g_shared_xhtml_entity_result[6] = 0x83;
g_shared_xhtml_entity_result[7] = 0x92;
entity_length_in_utf8 = 8;
} else {
DCHECK_LE(number_of_code_units, 4u);
entity_length_in_utf8 = ConvertUTF16EntityToUTF8(
utf16_decoded_entity, number_of_code_units,
reinterpret_cast<char*>(g_shared_xhtml_entity_result),
kSharedXhtmlEntityResultLength);
if (entity_length_in_utf8 == 0)
return nullptr;
}
DCHECK_LE(entity_length_in_utf8, kSharedXhtmlEntityResultLength);
xmlEntityPtr entity = SharedXHTMLEntity(); xmlEntityPtr entity = SharedXHTMLEntity();
entity->length = entity_length_in_utf8; entity->length = entity_length_in_utf8;
......
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