Fix crash when id attribute is set via SetAttributeNode

This commit is contained in:
Connor Brewster 2017-06-20 10:34:33 -06:00
parent 154186f420
commit 2ccf729aa3
3 changed files with 30 additions and 0 deletions

View file

@ -1543,6 +1543,10 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-setattributenode
fn SetAttributeNode(&self, attr: &Attr) -> Fallible<Option<Root<Attr>>> {
// Workaround for https://github.com/servo/servo/issues/17366
// This ensures that if this is an "id" attr, its value is an Atom
attr.swap_value(&mut self.parse_plain_attribute(attr.local_name(), attr.Value()));
// Step 1.
if let Some(owner) = attr.GetOwnerElement() {
if &*owner != self {

View file

@ -13024,6 +13024,12 @@
{}
]
],
"mozilla/element_setAttributeNode.html": [
[
"/_mozilla/mozilla/element_setAttributeNode.html",
{}
]
],
"mozilla/empty_clientrect.html": [
[
"/_mozilla/mozilla/empty_clientrect.html",
@ -25731,6 +25737,10 @@
"9ddf84332ca6efa6390315f20d59be2964a69dc7",
"testharness"
],
"mozilla/element_setAttributeNode.html": [
"4159931c8fc73a2305fa3d3bfe988132f38b4975",
"testharness"
],
"mozilla/empty_clientrect.html": [
"0860a059be4885f2b48de1aa7d87b8d0a7058195",
"testharness"

View file

@ -0,0 +1,16 @@
<!doctype html>
<meta charset="utf-8">
<title>Element setAttributeNode</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="test"></div>
<script>
test(function() {
var element = document.getElementById("test");
var attr = document.createAttribute("id");
attr.value = "foo";
element.setAttributeNode(attr);
var id = element.getAttribute("id");
assert_equals(id, "foo", "getAttribute should have value 'foo'");
});
</script>