Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix namespaces of elements created in XML documents #14095

Closed
nox opened this issue Nov 6, 2016 · 24 comments · Fixed by #16472
Closed

Fix namespaces of elements created in XML documents #14095

nox opened this issue Nov 6, 2016 · 24 comments · Fixed by #16472
Labels
A-content/dom Interacting with the DOM from web content C-assigned There is someone working on resolving the issue E-less-complex Straightforward. Recommended for a new contributor.

Comments

@nox
Copy link
Contributor

nox commented Nov 6, 2016

Step 6 of the spec is not correctly implemented, and elements created in XML documents also get the HTML namespace where they shouldn't.

Files:

  • components/script/dom/document.rs
  • tests/wpt/metadata/dom/nodes/Node-properties.html.ini
  • tests/wpt/web-platform-tests/dom/nodes/Node-properties.html
@nox nox added A-content/dom Interacting with the DOM from web content E-less-complex Straightforward. Recommended for a new contributor. labels Nov 6, 2016
@highfive
Copy link

highfive commented Nov 6, 2016

Please make a comment here if you intend to work on this issue. Thank you!

@nox
Copy link
Contributor Author

nox commented Nov 6, 2016

Blocks #2185.

@zimurgh
Copy link

zimurgh commented Nov 6, 2016

I would like to take this one!

@nox
Copy link
Contributor Author

nox commented Nov 6, 2016

Sure!

@nox nox added the C-assigned There is someone working on resolving the issue label Nov 6, 2016
@linclark
Copy link
Contributor

I saw this listed as potentially open on https://starters.servo.org/. If it is available, I'd like to give it a shot.

@jdm
Copy link
Member

jdm commented Nov 21, 2016

That sounds fine to me. @OldManMike, if you'd like to work on something else let us know and we'll find another issue for you.

@zimurgh
Copy link

zimurgh commented Nov 26, 2016

Sure, I'd be willing to pass this one off to @linclark!

@linclark
Copy link
Contributor

Thanks! I posted my work-in-progress. I ran into two issues, which I explain in the PR.

bors-servo pushed a commit that referenced this issue Dec 16, 2016
[WIP] Fix namespaces of elements created in XML documents

This is a work in progress.

Without this PR, all elements are created using the HTML namespace, even when createElement is called in an XML document. To fix this, I check `self.is_html_document` and assign the namespace based on that.

However, there were two problems with this approach:

1. It seems some documents that I would think are HTML documents aren't currently handled as such. See the condition I added in the second commit.
2. The last test in `Document-constructor.html` fails. I'm not sure whether the test is correct, though. I tried running something similar in Firefox DevEdition (replacing `assert_equals` with `console.log`) and it looks to me like that test would fail in Firefox as well.

```
  var doc = new Document();
  var a = doc.createElement("a");
  a.href = "http://example.org/?\u00E4";
  console.log(a.href, "http://example.org/?%C3%A4");
```

Result:
```
"http://example.org/?ä" "http://example.org/?%C3%A4"
```

---
<!-- 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 there are already tests which were being ignored.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14401)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this issue Dec 16, 2016
[WIP] Fix namespaces of elements created in XML documents

This is a work in progress.

Without this PR, all elements are created using the HTML namespace, even when createElement is called in an XML document. To fix this, I check `self.is_html_document` and assign the namespace based on that.

However, there were two problems with this approach:

1. It seems some documents that I would think are HTML documents aren't currently handled as such. See the condition I added in the second commit.
2. The last test in `Document-constructor.html` fails. I'm not sure whether the test is correct, though. I tried running something similar in Firefox DevEdition (replacing `assert_equals` with `console.log`) and it looks to me like that test would fail in Firefox as well.

```
  var doc = new Document();
  var a = doc.createElement("a");
  a.href = "http://example.org/?\u00E4";
  console.log(a.href, "http://example.org/?%C3%A4");
```

Result:
```
"http://example.org/?ä" "http://example.org/?%C3%A4"
```

---
<!-- 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 there are already tests which were being ignored.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14401)
<!-- Reviewable:end -->
@jdm jdm added the C-has-open-pr There is a PR open that resolves the issue label Jan 5, 2017
@jdm
Copy link
Member

jdm commented Jan 27, 2017

#14401 has a WIP solution, and there are some review comments that need to be addressed.

@jdm jdm removed C-assigned There is someone working on resolving the issue C-has-open-pr There is a PR open that resolves the issue labels Jan 27, 2017
@enizor
Copy link

enizor commented Feb 6, 2017

I would like to work on this issue!

@jdm
Copy link
Member

jdm commented Feb 6, 2017

Please do! Ask questions if anything is unclear.

@jdm jdm added the C-assigned There is someone working on resolving the issue label Feb 6, 2017
@enizor
Copy link

enizor commented Feb 7, 2017

I used @linclark's changes to understand the unpassed tests and her thoughts about modifying the doctype when XML documents are created.

The tests are failing on

PASS expected FAIL xmlElement.namespaceURI
PASS expected FAIL detachedXmlElement.namespaceURI 

I think that these tests are supposed to pass, and the expected: FAIL was added for some reason in #13210 (some form of acknowledgement? ). Deleting tests/wpt/metadata/dom/nodes/Node-properties.html.ini would do the trick in that case. What are your thoughts on this ?

Another question : Steps 3 and 6 of the spec (about the is attribute) aren't implemented. Is there a reason for this? Is it the matter of another issue?

@jdm
Copy link
Member

jdm commented Feb 7, 2017

Yes, the contents of the ini files reflect the status of the test on the master branch of Servo. PASS expected FAIL means that the test now passes correctly. Deleting the ini file is the correct thing to do.

@jdm
Copy link
Member

jdm commented Feb 7, 2017

The is member is specific to Custom Elements which we don't support yet.

@jdm
Copy link
Member

jdm commented Feb 23, 2017

@enizor Have you made any progress with this?

@enizor
Copy link

enizor commented Feb 23, 2017

I have a lot of trouble understanding the origin of the failed test pointed out in the PR.

I looked for other failed tests and found Document-createElement.html.

I changed the test as only HTML documents have the HTML namespace now.

assert_equals(elt.namespaceURI,
-                        desc == "XML document" ? null : HTMLNS, "namespaceURI")
+                        desc == "HTML document" ? HTMLNS : null, "namespaceURI")

All the tests results from Document-createElement.html are then expected.

I will take another look in the Document-constructor.html fail this week-end

@jdm
Copy link
Member

jdm commented Mar 4, 2017

@Ms2ger You're more familiar with the namespace stuff than me; could you answer the previous comment?

@enizor
Copy link

enizor commented Mar 5, 2017

Nevermind my previous comment, I realised that I misunderstood the HTML namespace usage. No changes for Document-createElement are needed.

@jdm
Copy link
Member

jdm commented Mar 21, 2017

@enizor How is it going? Still working on this?

@enizor
Copy link

enizor commented Mar 27, 2017

I still don't understand the test fail. I had some trouble running the tests (mach test is dependant of your last mach build, and not the current branch, right?) as the compilation is quite slow on my laptop. I think I should give up on this issue and try some stuff on my side, to make sure I understand more about the project and its tools. Then I may be able to tackle issues with a better efficiency!

@jdm
Copy link
Member

jdm commented Mar 27, 2017

Yeah, ./mach test relies on the previous completed build. I'll mark this as unassigned given you previous comment.

@jdm jdm removed the C-assigned There is someone working on resolving the issue label Mar 27, 2017
@cu1t
Copy link
Contributor

cu1t commented Apr 11, 2017

Hi everyone! I'm new to both rust and servo, but would like to try working on this issue as it is currently not assigned to anyone.

@jdm jdm added the C-assigned There is someone working on resolving the issue label Apr 11, 2017
@jdm
Copy link
Member

jdm commented Apr 11, 2017

Go ahead! Please ask questions if anything is unclear!

@cu1t
Copy link
Contributor

cu1t commented Apr 12, 2017

A bit unsure how to proceed here. As mentioned above and in @linclark's pull request, required changes result in Document-constructor.html test to fail:

var doc = new Document();
var a = doc.createElement("a");
a.href = "http://example.org/?\u00E4";
console.log(a.href, "http://example.org/?%C3%A4");

I'm not very familiar with the specs, but after giving them some look I tend to think that it is test at fault here. Created document will have contentType set to "application/xml", self.is_html_document will also be false -> empty namespace for createElement. So during element creation this should be treated just as XML. I don't see why this should encode URL then? I'm not 100% on this though, so should I perhaps raise issue at https://github.com/w3c/web-platform-tests?

bors-servo pushed a commit that referenced this issue Apr 16, 2017
Fix namespaces of elements created in XML documents

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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16472)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this issue Apr 16, 2017
Fix namespaces of elements created in XML documents

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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16472)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this issue Apr 20, 2017
Fix namespaces of elements created in XML documents

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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16472)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/dom Interacting with the DOM from web content C-assigned There is someone working on resolving the issue E-less-complex Straightforward. Recommended for a new contributor.
Projects
None yet
7 participants