mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Fix Element::GetAttribute()
Local names should not be used to get a attribute without providing a namespace.
This commit is contained in:
parent
f22d920b4d
commit
1906f835b9
2 changed files with 13 additions and 10 deletions
|
@ -610,6 +610,9 @@ pub trait AttributeHandlers {
|
||||||
/// name, if any.
|
/// name, if any.
|
||||||
fn get_attribute(self, namespace: Namespace, local_name: &Atom)
|
fn get_attribute(self, namespace: Namespace, local_name: &Atom)
|
||||||
-> Option<Temporary<Attr>>;
|
-> 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)
|
fn get_attributes(self, local_name: &Atom)
|
||||||
-> Vec<Temporary<Attr>>;
|
-> Vec<Temporary<Attr>>;
|
||||||
fn set_attribute_from_parser(self,
|
fn set_attribute_from_parser(self,
|
||||||
|
@ -651,6 +654,15 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||||
.map(|x| Temporary::from_rooted(x.r()))
|
.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>> {
|
fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>> {
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attrs = self.attrs.borrow();
|
let attrs = self.attrs.borrow();
|
||||||
|
@ -974,7 +986,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
||||||
// http://dom.spec.whatwg.org/#dom-element-getattribute
|
// http://dom.spec.whatwg.org/#dom-element-getattribute
|
||||||
fn GetAttribute(self, name: DOMString) -> Option<DOMString> {
|
fn GetAttribute(self, name: DOMString) -> Option<DOMString> {
|
||||||
let name = self.parsed_name(name);
|
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())
|
.map(|s| s.r().Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,8 @@
|
||||||
[attributes.html]
|
[attributes.html]
|
||||||
type: testharness
|
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.]
|
[When qualifiedName does not match the QName production, an NAMESPACE_ERR exception is to be thrown.]
|
||||||
expected: FAIL
|
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]
|
[Attribute with prefix in local name]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue