Preserve leading BOMs when parsing already-decoded HTML strings, since those strings do not go through the encoded byte decoder path. Decoded markup from JS strings can also contain WTF-8 for lone surrogate code units. Keep the common scalar UTF-8 path to a single validation and copy, but replace surrogates before handing bytes to the Rust tokenizer. Add text coverage for DOMParser and innerHTML string parsing, including leading BOMs, text and attributes, lone high and low surrogates, and a valid surrogate pair.
27 lines
1.1 KiB
HTML
27 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<script>
|
|
test(() => {
|
|
function dumpText(label, text) {
|
|
const codePoints = Array.from(text, character => character.codePointAt(0).toString(16)).join(",");
|
|
println(`${label}: length=${text.length}, codePoints=${codePoints}`);
|
|
}
|
|
|
|
const textMarkup = "\uFEFF\uD800A\uDC00B\uD83D\uDE00";
|
|
|
|
const parsedDocument = new DOMParser().parseFromString(textMarkup, "text/html");
|
|
dumpText("DOMParser text", parsedDocument.body.textContent);
|
|
|
|
const div = document.createElement("div");
|
|
div.innerHTML = textMarkup;
|
|
dumpText("innerHTML text", div.textContent);
|
|
|
|
const attributeMarkup = `<span title="${textMarkup}"></span>`;
|
|
|
|
const parsedAttributeDocument = new DOMParser().parseFromString(attributeMarkup, "text/html");
|
|
dumpText("DOMParser attribute", parsedAttributeDocument.body.firstChild.getAttribute("title"));
|
|
|
|
div.innerHTML = attributeMarkup;
|
|
dumpText("innerHTML attribute", div.firstChild.getAttribute("title"));
|
|
});
|
|
</script>
|