Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 730 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /dom/nodes/processing-instruction-attributes.html - WPT Dashboard Interop Dashboard
<!doctype html>
<meta charset="utf-8" />
<title>Processing instruction attributes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="container"><?t a="b" x="yy"?></div>
<script>
const sources = {
"html-dom": (target, data) =>
document.createProcessingInstruction(target, data),
"html-parser": (target, data) => {
const div = document.createElement("div");
div.innerHTML = `<?${target} ${data}?>`;
return div.firstChild;
},
"xml-dom": (target, data) =>
new DOMParser()
.parseFromString("<root></root>", "application/xml")
.createProcessingInstruction(target, data),
"xml-parser": (target, data) =>
new DOMParser().parseFromString(
`<?${target} ${data}?>`,
"application/xml",
).firstChild,
};
test(() => {
const div = document.getElementById("container");
const pi = div.firstChild;
assert_equals(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE);
assert_equals(pi.getAttribute("a"), "b");
assert_equals(pi.getAttribute("x"), "yy");
}, "Processing instruction in main parser");
for (const [source, createProcessingInstruction] of Object.entries(sources)) {
test(() => {
const pi = createProcessingInstruction("t", 'a=b x="yy"');
assert_false(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), []);
assert_equals(pi.getAttribute("a"), null);
assert_equals(pi.getAttribute("x"), null);
}, "Processing instruction attribute parsing rejects unquoted attributes from " + source);
// Per the rules for parsing pseudo-attributes from a string, the whole
// string has to match PseudoAtts and no name may appear twice. Any
// violation is an error, which makes the processing instruction have no
// attributes at all (rather than, say, the first or last duplicate winning).
for (const data of [
'name="p" name="q"',
'name="p" junk',
'junk name="p"',
'name="p"other="q"',
'name="p" ="q"',
'name="p" other=',
'name="p',
'name="p" other="q',
]) {
test(() => {
const pi = createProcessingInstruction("t", data);
assert_equals(pi.data, data, "data is preserved verbatim");
assert_false(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), []);
assert_false(pi.hasAttribute("name"));
assert_equals(pi.getAttribute("name"), null);
assert_false(pi.hasAttribute("other"));
assert_equals(pi.getAttribute("other"), null);
}, `Malformed pseudo-attributes ${JSON.stringify(data)} yield no attributes (source: ${source})`);
}
test(() => {
const pi = createProcessingInstruction("t", 'a="b" x="yy"');
const mutation_observer = new MutationObserver((records) => {});
mutation_observer.observe(pi, { characterData: true, attributes: true });
assert_equals(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE);
assert_equals(pi.target, "t");
assert_true(pi.hasAttributes());
assert_equals(pi.data, `a="b" x="yy"`);
assert_array_equals(pi.getAttributeNames(), ["a", "x"]);
assert_equals(pi.getAttribute("a"), "b");
assert_equals(pi.getAttribute("x"), "yy");
assert_equals(pi.getAttribute("X"), null);
assert_equals(pi.getAttribute("nada"), null);
assert_true(pi.hasAttribute("a"));
assert_false(pi.hasAttribute("nope"));
pi.setAttribute("x", "yy2");
let records = mutation_observer.takeRecords();
assert_equals(records.length, 1);
assert_equals(records[0].type, "characterData");
assert_equals(records[0].target, pi);
assert_equals(pi.data, `a="b" x="yy2"`);
assert_equals(pi.getAttribute("x"), "yy2");
pi.removeAttribute("x");
records = mutation_observer.takeRecords();
assert_equals(records.length, 1);
assert_equals(records[0].type, "characterData");
assert_equals(records[0].target, pi);
assert_equals(pi.getAttribute("x"), null);
assert_equals(pi.data, `a="b"`);
pi.setAttribute("z", "1");
pi.setAttribute("c", "2");
records = mutation_observer.takeRecords();
assert_equals(records.length, 2);
assert_equals(records[0].type, "characterData");
assert_equals(records[0].target, pi);
assert_equals(records[1].type, "characterData");
assert_equals(records[1].target, pi);
assert_equals(
pi.data,
`a="b" z="1" c="2"`,
"attributes are added in order",
);
assert_array_equals(pi.getAttributeNames(), ["a", "z", "c"]);
pi.setAttribute("a", "3");
assert_equals(
pi.data,
`a="3" z="1" c="2"`,
"setAttribute modifies attributes in place",
);
assert_array_equals(pi.getAttributeNames(), ["a", "z", "c"]);
pi.data = "";
assert_false(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), []);
pi.data = 'blabla=""';
assert_equals(pi.data, `blabla=""`);
assert_equals(pi.getAttribute("blabla"), "");
assert_equals(pi.getAttribute("BLABLA"), null);
assert_equals(pi.getAttribute("blaBLA"), null);
pi.setAttribute("BLAbla", "value");
assert_equals(pi.getAttribute("BLAbla"), "value");
assert_equals(pi.getAttribute("blabla"), "");
assert_true(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), ["blabla", "BLAbla"]);
pi.removeAttribute("BLABLA");
assert_true(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), ["blabla", "BLAbla"]);
pi.removeAttribute("blabla");
pi.removeAttribute("BLAbla");
assert_false(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), []);
}, "Processing instruction attribute mutation from " + source);
test(() => {
const pi = createProcessingInstruction("t", '_x="yy"');
assert_true(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), ["_x"]);
assert_equals(pi.getAttribute("_x"), "yy");
}, "Processing instruction attribute parsing allows _ in attribute names from " + source);
test(() => {
const pi = createProcessingInstruction("target", `attr="value"`);
assert_equals(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE);
assert_equals(pi.target, "target");
assert_equals(
pi.getAttribute("attr"),
"value",
"attribute value before toggling",
);
pi.toggleAttribute("attr", true);
assert_equals(
pi.getAttribute("attr"),
"value",
"toggleAttribute(true) does not change existing value",
);
pi.toggleAttribute("attr");
assert_false(
pi.hasAttribute("attr"),
"toggleAttribute() removes attribute",
);
assert_equals(pi.getAttribute("attr"), null);
pi.toggleAttribute("attr", false);
assert_false(
pi.hasAttribute("attr"),
"toggleAttribute(false) does not add attribute",
);
assert_equals(pi.getAttribute("attr"), null);
pi.toggleAttribute("attr");
assert_true(pi.hasAttribute("attr"), "toggleAttribute() adds attribute");
assert_equals(
pi.getAttribute("attr"),
"",
"toggleAttribute() adds attribute with empty value",
);
pi.toggleAttribute("attr", true);
assert_true(
pi.hasAttribute("attr"),
"toggleAttribute(true) does not remove attribute",
);
assert_equals(pi.getAttribute("attr"), "");
}, "Processing instruction toggleAttribute from " + source);
function test_valid_attribute_value(value) {
test(() => {
const pi = createProcessingInstruction("target", "");
pi.setAttribute("attr", value);
assert_true(pi.hasAttribute("attr"));
assert_equals(pi.getAttribute("attr"), value);
const escaped = value
.replaceAll("&", "&")
.replaceAll('"', """)
.replaceAll("<", "<")
.replaceAll(">", ">");
assert_equals(pi.data, `attr="${escaped}"`);
}, `Valid attribute value: ${format_value(value)} (source: ${source})`);
}
function test_invalid_attribute_value(value) {
test(() => {
const pi = createProcessingInstruction("target", "");
assert_throws_dom("InvalidCharacterError", () => {
pi.setAttribute("attr", value);
});
}, `Invalid attribute value: ${format_value(value)} (source: ${source})`);
}
function test_valid_attribute_name(name) {
test(() => {
const pi = createProcessingInstruction("target", "");
pi.setAttribute(name, "value");
assert_true(pi.hasAttribute(name));
assert_equals(pi.getAttribute(name), "value");
assert_array_equals(pi.getAttributeNames(), [name]);
// A name setAttribute() accepts matches Name, so it survives being parsed back out
// of data.
assert_equals(pi.data, `${name}="value"`);
pi.data = pi.data;
assert_equals(pi.getAttribute(name), "value");
pi.toggleAttribute(name, false);
assert_false(pi.hasAttribute(name));
pi.toggleAttribute(name, true);
assert_true(pi.hasAttribute(name));
assert_equals(pi.getAttribute(name), "");
pi.removeAttribute(name);
assert_false(pi.hasAttribute(name));
}, `Valid attribute name: ${format_value(name)} (source: ${source})`);
}
function test_invalid_attribute_name(name) {
test(() => {
const pi = createProcessingInstruction("target", "");
assert_throws_dom("InvalidCharacterError", () => {
pi.setAttribute(name, "value");
});
assert_throws_dom("InvalidCharacterError", () => {
pi.toggleAttribute(name, true);
});
assert_throws_dom("InvalidCharacterError", () => {
pi.toggleAttribute(name, false);
});
assert_throws_dom("InvalidCharacterError", () => {
pi.toggleAttribute(name);
});
}, `Invalid attribute name: ${format_value(name)} (source: ${source})`);
}
function test_distinct_attribute_name(name, other) {
test(
() => {
const pi = createProcessingInstruction("target", "");
pi.setAttribute(name, "value");
assert_false(pi.hasAttribute(other));
assert_true(pi.hasAttribute(name));
assert_equals(pi.getAttribute(other), null);
assert_equals(pi.getAttribute(name), "value");
pi.removeAttribute(other);
assert_true(pi.hasAttribute(name));
pi.removeAttribute(name);
assert_false(pi.hasAttribute(name));
},
"Distinct attribute name (source: " +
source +
"): " +
name +
" and " +
other,
);
}
// Name and Reference productions. These helpers parse data rather than calling
// setAttribute(), so they cover the other direction of the same grammar.
function test_valid_pseudo_att(data, name, value) {
test(() => {
const pi = createProcessingInstruction("t", data);
assert_equals(pi.data, data, "data is preserved verbatim");
assert_true(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), [name]);
assert_equals(pi.getAttribute(name), value);
}, `Valid pseudo-attribute: ${format_value(data)} (source: ${source})`);
}
function test_invalid_pseudo_att(data) {
test(() => {
const pi = createProcessingInstruction("t", data);
assert_equals(pi.data, data, "data is preserved verbatim");
assert_false(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), []);
}, `Invalid pseudo-attribute: ${format_value(data)} (source: ${source})`);
}
// A name that matches Name parses out of data, and one that does not is an error that
// leaves the processing instruction without attributes.
function test_valid_name_in_data(name) {
test_valid_pseudo_att(`${name}="1"`, name, "1");
}
function test_invalid_name_in_data(name) {
test_invalid_pseudo_att(`${name}="1"`);
}
// A value in data goes through the Reference production, so a character reference is
// resolved while a malformed or out-of-range one is an error.
function test_valid_value_in_data(literal, value) {
test_valid_pseudo_att(`a="${literal}"`, "a", value);
}
function test_invalid_value_in_data(literal) {
test_invalid_pseudo_att(`a="${literal}"`);
}
test_valid_attribute_value("");
test_valid_attribute_value("&");
test_valid_attribute_value('"');
test_valid_attribute_value("<");
test_valid_attribute_value(">");
// Escaped in XML attributes but not in PIs
test_valid_attribute_value("\t");
test_valid_attribute_value("\n");
test_valid_attribute_value("\r");
// Escaped in HTML attributes but not in PIs
test_valid_attribute_value("\u00A0");
// These should not be escaped
test_valid_attribute_value("=");
test_valid_attribute_value("'");
// [#x20-#xD7FF] boundaries and DEL/C1 controls
test_valid_attribute_value(" ");
test_valid_attribute_value("\x7F");
test_valid_attribute_value("\u0080");
test_valid_attribute_value("\uD7FF");
// [#xE000-#xFFFD] boundaries (including #xFDD0, allowed by XML's Char)
test_valid_attribute_value("\uE000");
test_valid_attribute_value("\uFDD0");
test_valid_attribute_value("\uFFFD");
// [#x10000-#x10FFFF] boundaries (surrogate pairs, including #xF0000 and #x10FFFF)
test_valid_attribute_value("\u{10000}");
test_valid_attribute_value("\u{F0000}");
test_valid_attribute_value("\u{10FFFE}");
test_valid_attribute_value("\u{10FFFF}");
// Code points excluded from XML's Char are rejected by setAttribute() per
// string, so it has no value check.
// Control characters excluded from XML's Char (#x0-#x8, #xB-#xC, #xE-#x1F)
test_invalid_attribute_value("\0");
test_invalid_attribute_value("a\0b");
test_invalid_attribute_value("\x08");
test_invalid_attribute_value("\x0B");
test_invalid_attribute_value("\f");
test_invalid_attribute_value("\x0E");
test_invalid_attribute_value("\x1F");
// Lone surrogates (#xD800-#xDFFF)
test_invalid_attribute_value("\uD800");
test_invalid_attribute_value("\uDFFF");
test_invalid_attribute_value("a\uD800b");
test_invalid_attribute_value("\uDC00\uD800");
// Noncharacters excluded from XML's Char (#xFFFE-#xFFFF)
test_invalid_attribute_value("\uFFFE");
test_invalid_attribute_value("\uFFFF");
test_invalid_attribute_value("a\uFFFEb");
// Empty, delimiter, whitespace, and null characters (also invalid as attribute local names)
test_invalid_attribute_name("");
test_invalid_attribute_name("=");
test_invalid_attribute_name("a=");
test_invalid_attribute_name("=x");
test_invalid_attribute_name("b>");
test_invalid_attribute_name(">");
test_invalid_attribute_name(">x");
test_invalid_attribute_name("/x/");
test_invalid_attribute_name("/");
test_invalid_attribute_name("x/");
test_invalid_attribute_name("x\t");
test_invalid_attribute_name("\tx");
test_invalid_attribute_name("x\n");
test_invalid_attribute_name("\nx");
test_invalid_attribute_name("x\r");
test_invalid_attribute_name("\rx");
test_invalid_attribute_name("x\f");
test_invalid_attribute_name("\fx");
test_invalid_attribute_name("x ");
test_invalid_attribute_name(" x");
test_invalid_attribute_name("x\0");
test_invalid_attribute_name("\0x");
// they do not match XML's Name production, even though they used to be valid attribute
// local names.
test_invalid_attribute_name("$");
test_invalid_attribute_name("$foo");
test_invalid_attribute_name("a$b");
test_invalid_attribute_name('a"b');
test_invalid_attribute_name("a'b");
test_invalid_attribute_name("a<b");
test_invalid_attribute_name("a&b");
test_invalid_attribute_name("a?b");
// XML NameChar characters that are not NameStartChar
test_invalid_attribute_name("-");
test_invalid_attribute_name("-foo");
test_invalid_attribute_name(".");
test_invalid_attribute_name(".foo");
test_invalid_attribute_name("0");
test_invalid_attribute_name("0foo");
test_invalid_attribute_name("\u00B7");
test_invalid_attribute_name("\u00B7a");
test_invalid_attribute_name("\u0300a");
test_invalid_attribute_name("\u203Fa");
// Non-ASCII, surrogate, and astral code points excluded from NameStartChar and NameChar
test_invalid_attribute_name("\u00AA"); // below #xC0 (excluding #xB7)
test_invalid_attribute_name("a\u00AA");
test_invalid_attribute_name("\u00BA");
test_invalid_attribute_name("a\u00BA");
test_invalid_attribute_name("\u00D7"); // between #xC0-#xD6 and #xD8-#xF6
test_invalid_attribute_name("a\u00D7");
test_invalid_attribute_name("\u00F7"); // between #xD8-#xF6 and #xF8-#x2FF
test_invalid_attribute_name("a\u00F7");
test_invalid_attribute_name("\u037E"); // between #x370-#x37D and #x37F-#x1FFF
test_invalid_attribute_name("\u2000"); // between #x1FFF and #x200C-#x200D
test_invalid_attribute_name("\uD800"); // lone surrogate (#xD800-#xDFFF)
test_invalid_attribute_name("\uFFFE"); // noncharacters above #xFDF0-#xFFFD
test_invalid_attribute_name("\uFFFF");
test_invalid_attribute_name("\u{F0000}"); // Supplementary Private Use above #x10000-#xEFFFF
test_invalid_attribute_name("\u{10FFFF}");
// ASCII NameStartChar ("_" and ":", including names not matching QName)
test_valid_attribute_name("_");
test_valid_attribute_name("_bar");
test_valid_attribute_name("a_b");
test_valid_attribute_name(":");
test_valid_attribute_name(":foo");
test_valid_attribute_name("foo:");
test_valid_attribute_name("a:b");
test_valid_attribute_name("a:b:c");
// NameChar-only characters after a NameStartChar
test_valid_attribute_name("a-b");
test_valid_attribute_name("a.b");
test_valid_attribute_name("a0");
test_valid_attribute_name("a\u00B7b");
test_valid_attribute_name("a\u0300b");
test_valid_attribute_name("a\u203Fb");
// Non-ASCII and astral NameStartChar ranges
test_valid_attribute_name("\u00C0"); // #xC0-#xD6
test_valid_attribute_name("\u0370"); // #x370-#x37D
test_valid_attribute_name("\u3001"); // #x3001-#xD7FF
test_valid_attribute_name("\uFFFD"); // top of #xFDF0-#xFFFD
test_valid_attribute_name("\u{10000}"); // #x10000-#xEFFFF
test_valid_attribute_name("\u{1F600}");
test_valid_attribute_name("\u{EFFFF}");
test_distinct_attribute_name("ABC", "abc");
test_distinct_attribute_name("abC", "abc");
test_distinct_attribute_name("x123A", "x123a");
// Names in data that match XML's Name production, including names that are not QNames
test_valid_name_in_data("_a");
test_valid_name_in_data(":a");
test_valid_name_in_data("a:b");
test_valid_name_in_data("a-b");
test_valid_name_in_data("a.b");
test_valid_name_in_data("a0");
test_valid_name_in_data("a:-b");
test_valid_name_in_data("a\u00B7");
test_valid_name_in_data("\u00C0");
test_valid_name_in_data("\uFFFD");
test_valid_name_in_data("\u{10000}");
// Names in data that do not match Name
test_invalid_name_in_data("$");
test_invalid_name_in_data("$foo");
test_invalid_name_in_data("a$b");
test_invalid_name_in_data("1a");
test_invalid_name_in_data("-a");
test_invalid_name_in_data(".a");
test_invalid_name_in_data("\u00D7");
test_invalid_name_in_data("\u00B7a");
test_invalid_name_in_data("\u{F0000}");
// CharRef is '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';', and the referenced character has
// to match Char.
test_valid_value_in_data("A", "A");
test_valid_value_in_data("A", "A");
test_valid_value_in_data("A", "A");
test_valid_value_in_data("J", "J");
test_valid_value_in_data("J", "J");
test_valid_value_in_data("	", "\t");
test_valid_value_in_data("", "\uFDD0"); // noncharacter allowed by Char
test_valid_value_in_data("�", "\uFFFD");
test_valid_value_in_data("𐀀", "\u{10000}");
test_valid_value_in_data("", "\u{10FFFF}");
// The predefined entities, which EntityRef allows in a pseudo-attribute value
test_valid_value_in_data("&", "&");
test_valid_value_in_data("<", "<");
test_valid_value_in_data(">", ">");
test_valid_value_in_data(""", '"');
test_valid_value_in_data("'", "'");
// The replacement text of a reference is not rescanned for further references
test_valid_value_in_data("&lt;", "<");
test_valid_value_in_data("&#65;", "A");
// Malformed references
test_invalid_value_in_data("&# 65;");
test_invalid_value_in_data("&#+65;");
test_invalid_value_in_data("A"); // uppercase X
test_invalid_value_in_data("&#;");
test_invalid_value_in_data("&#x;");
test_invalid_value_in_data("&#xZZ;");
test_invalid_value_in_data("A"); // no semicolon
test_invalid_value_in_data("&");
test_invalid_value_in_data("&");
test_invalid_value_in_data("&");
test_invalid_value_in_data("&unknown;");
// Referenced characters that do not match Char, including values that overflow
test_invalid_value_in_data("�");
test_invalid_value_in_data("");
test_invalid_value_in_data("�");
test_invalid_value_in_data("");
test_invalid_value_in_data("�");
test_invalid_value_in_data("�");
test_invalid_value_in_data("�");
// Literal characters in a value: neither xml-stylesheet nor DOM normalizes whitespace,
// and '>' needs no escaping, while '<' has to be a reference.
// CR is left out because the HTML parser normalizes newlines in data.
test_valid_value_in_data("a\tb", "a\tb");
test_valid_value_in_data("a\nb", "a\nb");
test_valid_value_in_data(">", ">");
test_invalid_value_in_data("<");
test(() => {
// This data would be normalized to `a="b" c="d"` if it went through
// "update data from attributes".
const data = `a='b' c = "d"`;
const pi = createProcessingInstruction("t", data);
assert_equals(pi.data, data);
assert_array_equals(pi.getAttributeNames(), ["a", "c"]);
const mutation_observer = new MutationObserver(() => {});
// Observe attributes too so the test fails if an implementation
// erroneously queues an "attributes" mutation record for PI attributes.
mutation_observer.observe(pi, { characterData: true, attributes: true });
pi.removeAttribute("x");
assert_equals(pi.data, data, "removeAttribute() doesn't change data");
assert_false(pi.toggleAttribute("x", false));
assert_equals(pi.data, data, "toggleAttribute(name, false) doesn't change data");
assert_array_equals(pi.getAttributeNames(), ["a", "c"]);
assert_equals(
mutation_observer.takeRecords().length,
0,
"no mutation records",
);
const malformed = "a=b";
const malformed_pi = createProcessingInstruction("t", malformed);
mutation_observer.observe(malformed_pi, { characterData: true, attributes: true });
malformed_pi.removeAttribute("a");
assert_equals(malformed_pi.data, malformed, "removeAttribute() doesn't wipe malformed data");
assert_false(malformed_pi.toggleAttribute("a", false));
assert_equals(malformed_pi.data, malformed, "toggleAttribute(name, false) doesn't wipe malformed data");
assert_equals(
mutation_observer.takeRecords().length,
0,
"no mutation records on malformed PI",
);
}, "Removing a non-existent PI attribute doesn't normalize data from " + source);
// HTML parser ignores xml-stylesheet
if (source == "html-parser")
continue;
test(() => {
const pi = createProcessingInstruction(
"xml-stylesheet",
`type="text/css" href="style.css"`,
);
assert_equals(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE);
assert_equals(pi.target, "xml-stylesheet");
assert_equals(pi.data, `type="text/css" href="style.css"`);
assert_true(pi.hasAttributes());
assert_equals(pi.getAttribute("type"), "text/css");
assert_equals(pi.getAttribute("href"), "style.css");
assert_equals(pi.getAttribute("nada"), null);
assert_true(pi.hasAttribute("type"));
assert_false(pi.hasAttribute("nope"));
pi.setAttribute("href", "style2.css");
assert_equals(pi.getAttribute("href"), "style2.css");
pi.removeAttribute("href");
assert_equals(pi.getAttribute("href"), null);
assert_array_equals(pi.getAttributeNames(), ["type"]);
assert_true(pi.hasAttributes());
pi.data = 'type="text/css" href="style3.css"';
assert_equals(pi.getAttribute("type"), "text/css");
assert_equals(pi.getAttribute("href"), "style3.css");
assert_array_equals(pi.getAttributeNames(), ["type", "href"]);
}, "Processing instruction attributes with xml-stylesheet from " + source);
}
test(() => {
const pi = sources["html-parser"]("target", 'name="a\0b"');
assert_equals(pi.data, 'name="a\uFFFDb"');
assert_true(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), ["name"]);
assert_equals(pi.getAttribute("name"), "a\uFFFDb");
const pi_name = sources["html-parser"]("target", '\0="c"');
assert_equals(pi_name.data, '\uFFFD="c"');
assert_true(pi_name.hasAttributes());
assert_array_equals(pi_name.getAttributeNames(), ["\uFFFD"]);
assert_equals(pi_name.getAttribute("\uFFFD"), "c");
}, "U+0000 NULL in processing instruction data is replaced with U+FFFD in HTML parser");
// "xml-parser" is omitted because U+0000 is not a valid XML Char and
// produces a parse error rather than a ProcessingInstruction node.
for (const source of ["html-dom", "xml-dom"]) {
test(() => {
const pi = sources[source]("target", 'name="a\0b"');
assert_equals(pi.data, 'name="a\0b"');
assert_false(pi.hasAttributes());
assert_array_equals(pi.getAttributeNames(), []);
assert_equals(pi.getAttribute("name"), null);
}, `U+0000 NULL in processing instruction data invalidates pseudo-attributes from ${source}`);
}
</script>