Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 43 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /sanitizer-api/sanitizer-processing-instructions.tentative.html - WPT Dashboard Interop Dashboard
<!doctype html>
<head>
<title>Sanitizer API: Processing Instructions</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/html5lib-testcase-support.js"></script>
<script id="agnostic" type="html5lib-testcases">
#data
<?target data?>
#config
{ "processingInstructions": ["target"] }
#document
| <?target data>
#data
<?target data?>
#config
{ "processingInstructions": [{ "target": "target" }] }
#document
| <?target data>
#data
<?Target data?>
#config
{ "processingInstructions": ["target"] }
#document
| <?target data>
#data
<?target data?>
#config
{ "processingInstructions": ["Target"] }
#document
#data
<?target-1 data?><?target-2 data?>
#config
{ "processingInstructions": ["target-1", "target-2"] }
#document
| <?target-1 data>
| <?target-2 data>
#data
<?target-1 data?><?target-2 data?>
#config
{ "processingInstructions": ["target-1"] }
#document
| <?target-1 data>
#data
<div><?target data?></div>
#config
{ "processingInstructions": ["target"] }
#document
| <div>
| <?target data>
</script>
<script id="unsafe-only" type="html5lib-testcases">
#data
<?target data?>
#config
{ "removeProcessingInstructions": ["target"] }
#document
#data
<?target data?>
#config
{ "removeProcessingInstructions": [{ "target": "target" }] }
#document
#data
<div><?target data?></div>
#config
{ "removeProcessingInstructions": ["target"] }
#document
| <div>
#data
<div><?target data?></div>
#config
{}
#document
| <div><?target data?></div>
</script>
<script id="safe-only" type="html5lib-testcases">
#data
<div><?target data?></div>
#config
{}
#document
| <div></div>
</script>
<script>
for (const group of document.querySelectorAll(
"script[type='html5lib-testcases']",
)) {
const type = group.id;
parse_html5lib_testcases(group.textContent).forEach((testcase, index) => {
let config = undefined;
if (testcase.config) {
config = { sanitizer: JSON.parse(testcase.config) };
}
if (type !== "safe-only") {
test((_) => {
const div = document.createElement("div");
div.setHTMLUnsafe(testcase.data, config);
assert_testcase(div, testcase);
}, `setHTMLUnsafe testcase ${group.id}/${index}, "${testcase.data}"`);
test((_) => {
const div = document.createElement("div");
const shadowRoot = div.attachShadow({ mode: "open" });
shadowRoot.setHTMLUnsafe(testcase.data, config);
assert_testcase(shadowRoot, testcase);
}, `ShadowRoot.setHTMLUnsafe testcase ${group.id}/${index}, "${testcase.data}"`);
}
if (type !== "unsafe-only") {
test((_) => {
const div = document.createElement("div");
div.setHTML(testcase.data, config);
assert_testcase(div, testcase);
}, `setHTML testcase ${group.id}/${index}, "${testcase.data}"`);
test((_) => {
const div = document.createElement("div");
const shadowRoot = div.attachShadow({ mode: "open" });
shadowRoot.setHTML(testcase.data, config);
assert_testcase(shadowRoot, testcase);
}, `ShadowRoot.setHTML testcase ${group.id}/${index}, "${testcase.data}"`);
}
// parseHTML and parseHTMLUnsafe need to allow "html" and "body" for these
// tests to be useful. Update the config, if necessary.
let parse_config = config;
if (config && config["sanitizer"]) {
parse_config = { sanitizer: new Sanitizer(config["sanitizer"]) };
parse_config["sanitizer"].allowElement("body");
parse_config["sanitizer"].allowElement("html");
}
if (type !== "unsafe-only") {
test((_) => {
// Wrap in a div to ensure the processing instruction goes into the body.
const doc = Document.parseHTML(`<div>${testcase.data}</div>`, parse_config);
assert_testcase(doc.body.firstChild, testcase);
}, `parseHTML testcase ${group.id}/${index}, "${testcase.data}"`);
}
if (type !== "safe-only") {
test((_) => {
// Wrap in a div to ensure the processing instruction goes into the body.
const doc = Document.parseHTMLUnsafe(
`<div>${testcase.data}</div>`,
parse_config,
);
assert_testcase(doc.body.firstChild, testcase);
}, `parseHTMLUnsafe testcase ${group.id}/${index}, "${testcase.data}"`);
}
});
}
</script>
</head>
<body></body>