servo: Merge #16472 - Fix namespaces of elements created in XML documents (from cu1t:#14095-fix-xml-doc-namespaces); r=nox
authorcu1t <umnov.pa@gmail.com>
Thu, 20 Apr 2017 01:01:05 -0500
changeset 354023 b06e3d6c2f783a505108f677fa773fc60f2cc2bb
parent 354022 488534f69bf5083ce6f898e508da30d6419f7869
child 354024 b01181410a8a8dcc757f39fad165d22e927ef3c0
push id31685
push userkwierso@gmail.com
push dateThu, 20 Apr 2017 21:45:29 +0000
treeherdermozilla-central@5e3dc7e1288a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #16472 - Fix namespaces of elements created in XML documents (from cu1t:#14095-fix-xml-doc-namespaces); r=nox Correctly implement following step of [Dom Document Spec](https://dom.spec.whatwg.org/#dom-document-createelement): > Let namespace be the HTML namespace, if the context object is an HTML document or context object’s content type is "application/xhtml+xml", and null otherwise. Note, this will make following test in `tests/wpt/web-platform-tests/dom/nodes/Document-constructor.html` to fail, so related .ini file added to mark it as such: ``` test(function() { var doc = new Document(); var a = doc.createElement("a"); // In UTF-8: 0xC3 0xA4 a.href = "http://example.org/?\u00E4"; assert_equals(a.href, "http://example.org/?%C3%A4"); }, "new Document(): URL parsing") ``` I'm not very familiar with specs, but from quick look at it, I'm doubtfull that it is valid in the first place. This is an "application/xml" document, so I don't see why it should encode a.href. Firefox also fails that. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #14095 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because because there are already tests which were being ignored <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 2d732d829b3fc93938898118ee55ef985ebfc657
servo/components/script/dom/document.rs
--- a/servo/components/script/dom/document.rs
+++ b/servo/components/script/dom/document.rs
@@ -2767,17 +2767,24 @@ impl DocumentMethods for Document {
     fn CreateElement(&self, mut local_name: DOMString) -> Fallible<Root<Element>> {
         if xml_name_type(&local_name) == InvalidXMLName {
             debug!("Not a valid element name");
             return Err(Error::InvalidCharacter);
         }
         if self.is_html_document {
             local_name.make_ascii_lowercase();
         }
-        let name = QualName::new(ns!(html), LocalName::from(local_name));
+
+        let ns = if self.is_html_document || self.content_type == "application/xhtml+xml" {
+            ns!(html)
+        } else {
+            ns!()
+        };
+
+        let name = QualName::new(ns, LocalName::from(local_name));
         Ok(Element::create(name, None, self, ElementCreator::ScriptCreated))
     }
 
     // https://dom.spec.whatwg.org/#dom-document-createelementns
     fn CreateElementNS(&self,
                        namespace: Option<DOMString>,
                        qualified_name: DOMString)
                        -> Fallible<Root<Element>> {