Skip to content

Commit

Permalink
Auto merge of #23192 - jackxbritton:issue-23134, r=jdm
Browse files Browse the repository at this point in the history
Implement DocumentFragment XML serialization.

When serializing a DocumentFragment node, we should follow [this guy](https://w3c.github.io/DOM-Parsing/#dfn-xml-serializing-a-documentfragment-node) and serialize the node's immediate children. This commit makes that change.

---
<!-- 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 #23134 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___ well, they probably do, but I don't know how to do that and could use some help.

<!-- 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/23192)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Apr 12, 2019
2 parents 8318624 + 1dd1cb4 commit 9832fed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion components/script/dom/servoparser/html.rs
Expand Up @@ -10,6 +10,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::trace::JSTraceable;
use crate::dom::characterdata::CharacterData;
use crate::dom::document::Document;
use crate::dom::documentfragment::DocumentFragment;
use crate::dom::documenttype::DocumentType;
use crate::dom::element::Element;
use crate::dom::htmlscriptelement::HTMLScriptElement;
Expand Down Expand Up @@ -166,7 +167,7 @@ fn rev_children_iter(n: &Node) -> impl Iterator<Item = DomRoot<Node>> {
impl SerializationIterator {
fn new(node: &Node, skip_first: bool) -> SerializationIterator {
let mut ret = SerializationIterator { stack: vec![] };
if skip_first {
if skip_first || node.is::<DocumentFragment>() {
for c in rev_children_iter(node) {
ret.push_node(&*c);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/wpt/metadata/MANIFEST.json
Expand Up @@ -642622,7 +642622,7 @@
"support"
],
"domparsing/XMLSerializer-serializeToString.html": [
"cb8ed9372df5e05588cbd593c40a8c13ee868bec",
"23b9ce841f5046f180ce78d92d7ac1132712f999",
"testharness"
],
"domparsing/createContextualFragment.html": [
Expand Down
Expand Up @@ -204,6 +204,14 @@ <h1>domparsing_XMLSerializer_serializeToString</h1>
assert_equals(serialize(root2), '<root xmlns:xl="http://www.w3.org/1999/xlink" xl:type="v"/>');
}, 'Check if no special handling for XLink namespace unlike HTML serializer.');

test(function() {
var root = new DocumentFragment;
root.append(document.createElement('div'));
root.append(document.createElement('span'));
assert_equals(serialize(root), '<div xmlns="http://www.w3.org/1999/xhtml"></div><span xmlns="http://www.w3.org/1999/xhtml"></span>');
}, 'Check if document fragment serializes.');


</script>
</body>
</html>

0 comments on commit 9832fed

Please sign in to comment.