Fix Element::GetAttribute()

Local names should not be used to get a attribute without providing a namespace.
This commit is contained in:
Anthony Ramine 2015-04-03 13:51:39 +02:00
parent f22d920b4d
commit 1906f835b9
2 changed files with 13 additions and 10 deletions

View file

@ -610,6 +610,9 @@ pub trait AttributeHandlers {
/// name, if any.
fn get_attribute(self, namespace: Namespace, local_name: &Atom)
-> Option<Temporary<Attr>>;
/// Returns the first attribute with any namespace and given case-sensitive
/// name, if any.
fn get_attribute_by_name(self, name: &Atom) -> Option<Temporary<Attr>>;
fn get_attributes(self, local_name: &Atom)
-> Vec<Temporary<Attr>>;
fn set_attribute_from_parser(self,
@ -651,6 +654,15 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
.map(|x| Temporary::from_rooted(x.r()))
}
fn get_attribute_by_name(self, name: &Atom) -> Option<Temporary<Attr>> {
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let attrs = self.attrs.borrow();
attrs.iter().map(|attr| attr.root())
.find(|a| a.r().name() == name)
.map(|x| Temporary::from_rooted(x.r()))
}
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>> {
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let attrs = self.attrs.borrow();
@ -974,7 +986,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
// http://dom.spec.whatwg.org/#dom-element-getattribute
fn GetAttribute(self, name: DOMString) -> Option<DOMString> {
let name = self.parsed_name(name);
self.get_attribute(ns!(""), &Atom::from_slice(&name)).root()
self.get_attribute_by_name(&Atom::from_slice(&name)).root()
.map(|s| s.r().Value())
}

View file

@ -1,17 +1,8 @@
[attributes.html]
type: testharness
[setAttribute should set the attribute with the given qualified name]
expected: FAIL
[When qualifiedName does not match the QName production, an NAMESPACE_ERR exception is to be thrown.]
expected: FAIL
[First set attribute is returned by getAttribute]
expected: FAIL
[First set attribute is returned with mapped attribute set later]
expected: FAIL
[Attribute with prefix in local name]
expected: FAIL