Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE html>
<meta charset="utf-8">
<title>Spurious attributes in DOMParser</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
test(() => {
const html = `<div title="this-should-not-be-an-attribute=1>"hello"></div>`;
const doc = new DOMParser().parseFromString(html, "text/html");
const div = doc.querySelector("div");
assert_false(div.hasAttribute("this-should-not-be-an-attribute"));
assert_equals(div.getAttribute("title"), 'this-should-not-be-an-attribute=1>"hello');
}, 'Using ">" and HTML entities in an attribute creates no unexpected attributes.');
test(() => {
const html = `<div title="this-should-not-be-an-attribute=1>\rhello"></div>`;
const doc = new DOMParser().parseFromString(html, "text/html");
const div = doc.querySelector("div");
assert_false(div.hasAttribute("this-should-not-be-an-attribute"));
assert_equals(div.getAttribute("title"), 'this-should-not-be-an-attribute=1>\nhello');
}, 'Using ">" and "\\r" in an attribute creates no unexpected attributes.');
</script>