Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions sanitizer-api/sanitizer-custom-elements-is.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>

let constructor_called = false;
let connectedCallback_called = false;

class FooBarElement extends HTMLDivElement {
constructor() {
super();
constructor_called = true;
}

connectedCallback() {
connectedCallback_called = true;
}
}

customElements.define("foo-bar", FooBarElement, { extends: "div" });

function assert_removed(sanitizer) {
constructor_called = connectedCallback_called = false;

let d = document.createElement("div");
document.body.append(d);
d.setHTML(`<div is="foo-bar">hello</div>`, { sanitizer } );
assert_equals(d.innerHTML, `<div>hello</div>`);
assert_false(d.firstChild.hasAttribute("is"));
assert_true(d.firstChild.matches(":defined"));

assert_false(constructor_called);
assert_false(connectedCallback_called);

d.remove();
}

test(t => {
assert_removed("default");
}, "The is= attribute is removed by the default sanitizer config.");

test(t => {
assert_removed({ removeAttributes: ["is"] });
}, "The is= attribute is removed by the global removeAttributes");

test(t => {
assert_removed({ elements: [{ name: "div", removeAttributes: ["is"] }], removeAttributes: [] });
}, "The is= attribute is removed by the local removeAttributes");

test(t => {
assert_removed({ elements: [{ name: "div", attributes: [] }], attributes: [] });
}, "The is= attribute is removed by the local missing attributes");

function assert_kept(sanitizer) {
constructor_called = connectedCallback_called = false;

let d = document.createElement("div");
document.body.append(d);
d.setHTML(`<div is="foo-bar">hello</div>`, { sanitizer });
assert_equals(d.innerHTML, `<div is="foo-bar">hello</div>`);
assert_true(d.firstChild.hasAttribute("is"));
assert_true(d.firstChild.matches(":defined"));

// "is" is re-created even after removing the attribute.
d.firstChild.removeAttribute("is");
assert_equals(d.innerHTML, `<div is="foo-bar">hello</div>`);

assert_true(constructor_called);
assert_true(connectedCallback_called);

d.remove();
}

test(t => {
assert_kept({ })
}, "The is= attribute is kept when allowed with an empty config.");

test(t => {
assert_kept({ attributes: ["is"] })
}, "The is= attribute is kept when allowed by global attributes.");

test(t => {
assert_kept({ removeAttributes: [] })
}, "The is= attribute is kept when allowed by global removeAttributes.");

test(t => {
assert_kept({ elements: [{ name: "div", attributes: ["is"] }], attributes: [] });
}, "The is= attribute is kept when allowed by local attributes.");
</script>
</body>
</html>
35 changes: 0 additions & 35 deletions sanitizer-api/sanitizer-unknown.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,6 @@
{ sanitizer: { attributes: ["hello", "world"] } });
assert_equals(d.innerHTML, `<b hello="1" world=""></b>`);
}, "Unknown attribute names pass when allowed.");

test(t => {
let d = document.createElement("div")
d.setHTML(`<div is="foo-bar">hello</div>`);
assert_equals(d.innerHTML, `<div>hello</div>`);
assert_false(d.firstChild.hasAttribute("is"));
assert_true(d.firstChild.matches(":defined"));
}, "The is= attribute is removed by the default sanitizer config.");

test(t => {
let d = document.createElement("div")
d.setHTML(`<span is="foo-bar">hello</span>`);
assert_equals(d.innerHTML, `<span>hello</span>`);
assert_false(d.firstChild.hasAttribute("is"));
assert_true(d.firstChild.matches(":defined"));
}, "The is= attribute is removed from span by the default sanitizer config.");


test(t => {
let d = document.createElement("div")
d.setHTML(`<div is="foo-bar">hello</div>`,
{ sanitizer: { attributes: ["is"] } });
assert_equals(d.innerHTML, `<div is="foo-bar">hello</div>`);
assert_true(d.firstChild.hasAttribute("is"));
assert_false(d.firstChild.matches(":defined"));
}, "The is= attribute is kept when explicitly allowed.");

test(t => {
let d = document.createElement("div")
d.setHTML(`<div is="foo-bar">hello</div>`,
{ sanitizer: { attributes: [] } });
assert_equals(d.innerHTML, `<div>hello</div>`);
assert_false(d.firstChild.hasAttribute("is"));
assert_true(d.firstChild.matches(":defined"));
}, "The is= attribute gets blocked with a custom config.");
</script>
</body>
</html>
Loading