From d0e095a3e5fee47d65cd5cf08cc9644223c2b64b Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 13 Sep 2014 11:00:36 +0200 Subject: Stop messing with the case of the attribute name in AttributeHandlers::get_attribute. This fixes a bug where GetAttributeNS would incorrectly match lower-case attributes when called with an upper-case argument. --- components/script/dom/element.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'components/script/dom') diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 30b2601f04e..2150e67f0eb 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -252,7 +252,10 @@ impl<'a> ElementHelpers for JSRef<'a, Element> { } pub trait AttributeHandlers { - fn get_attribute(&self, namespace: Namespace, name: &str) -> Option>; + /// Returns the attribute with given namespace and case-sensitive local + /// name, if any. + fn get_attribute(&self, namespace: Namespace, local_name: &str) + -> Option>; fn set_attribute_from_parser(&self, local_name: Atom, value: DOMString, namespace: Namespace, prefix: Option); @@ -282,13 +285,9 @@ pub trait AttributeHandlers { } impl<'a> AttributeHandlers for JSRef<'a, Element> { - fn get_attribute(&self, namespace: Namespace, name: &str) -> Option> { - let element: &Element = self.deref(); - let local_name = match self.html_element_in_html_document() { - true => Atom::from_slice(name.to_ascii_lower().as_slice()), - false => Atom::from_slice(name) - }; - element.attrs.borrow().iter().map(|attr| attr.root()).find(|attr| { + fn get_attribute(&self, namespace: Namespace, local_name: &str) -> Option> { + let local_name = Atom::from_slice(local_name); + self.attrs.borrow().iter().map(|attr| attr.root()).find(|attr| { *attr.local_name() == local_name && attr.namespace == namespace }).map(|x| Temporary::from_rooted(&*x)) } @@ -423,6 +422,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn get_url_attribute(&self, name: &str) -> DOMString { + assert!(name == name.to_ascii_lower().as_slice()); // XXX Resolve URL. self.get_string_attribute(name) } @@ -431,6 +431,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn get_string_attribute(&self, name: &str) -> DOMString { + assert!(name == name.to_ascii_lower().as_slice()); match self.get_attribute(Null, name) { Some(x) => { let x = x.root(); -- cgit v1.2.3