diff options
author | Ms2ger <ms2ger@gmail.com> | 2014-04-07 22:35:13 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2014-04-08 20:17:15 +0200 |
commit | d665ad5a179ce5623d023a24be7fb86d78ba3072 (patch) | |
tree | d91af766b6f017258b4b931e520760fc46dc6ed1 /src | |
parent | bf73a47ce0216683f6e65dbf281975f26877aeea (diff) | |
download | servo-d665ad5a179ce5623d023a24be7fb86d78ba3072.tar.gz servo-d665ad5a179ce5623d023a24be7fb86d78ba3072.zip |
Reimplement SetAttributeNS.
Diffstat (limited to 'src')
-rw-r--r-- | src/components/script/dom/element.rs | 48 | ||||
-rw-r--r-- | src/test/content/test_element_attribute.html | 10 |
2 files changed, 56 insertions, 2 deletions
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 9ecb10641b4..22a2c7a7771 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -324,15 +324,59 @@ impl AttributeHandlers for JS<Element> { fn SetAttributeNS(&mut self, namespace_url: Option<DOMString>, name: DOMString, value: DOMString) -> ErrorResult { + let node: JS<Node> = NodeCast::from(self); + node.get().wait_until_safe_to_modify_dom(); + + // Step 1. + let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url)); + let name_type = xml_name_type(name); match name_type { + // Step 2. InvalidXMLName => return Err(InvalidCharacter), + // Step 3. Name => return Err(NamespaceError), QName => {} } - let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url)); - self.set_attribute(namespace, name, value) + // Step 4. + let (prefix, local_name) = get_attribute_parts(name.clone()); + match prefix { + Some(ref prefix_str) => { + // Step 5. + if namespace == namespace::Null { + return Err(NamespaceError); + } + + // Step 6. + if "xml" == prefix_str.as_slice() && namespace != namespace::XML { + return Err(NamespaceError); + } + + // Step 7b. + if "xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS { + return Err(NamespaceError); + } + }, + None => {} + } + + // Step 7a. + if "xmlns" == name && namespace != namespace::XMLNS { + return Err(NamespaceError); + } + + // Step 8. + if namespace == namespace::XMLNS && "xmlns" != name && Some(~"xmlns") != prefix { + return Err(NamespaceError); + } + + // Step 9. + self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| { + attr.get().local_name == local_name && + attr.get().namespace == namespace + }); + Ok(()) } fn after_set_attr(&mut self, local_name: DOMString, value: DOMString) { diff --git a/src/test/content/test_element_attribute.html b/src/test/content/test_element_attribute.html index 7455f36bffb..d7ee6a23640 100644 --- a/src/test/content/test_element_attribute.html +++ b/src/test/content/test_element_attribute.html @@ -50,6 +50,16 @@ is_not(r2, null, "test5-1, Element.setAttribute('xml:lang')."); } + should_throw(function () { + test.setAttributeNS("http://example.com", "xmlns", "foo"); + }); + should_throw(function () { + test.setAttributeNS("http://www.w3.org/2000/xmlns/", "attr", "value"); + }); + should_throw(function () { + test.setAttributeNS("http://www.w3.org/2000/xmlns/", "prefix:attr", "value"); + }); + finish(); </script> </body> |