servo: Merge #16010 - Properly coalesce whitespace when given a reference child (fixes #15979) (from nox:h5e); r=KiChjang
authorAnthony Ramine <n.oxyde@gmail.com>
Fri, 17 Mar 2017 04:25:20 -0700
changeset 348150 1da2122f3597fc4ab0c913152f98c47ee1b4ec99
parent 348149 bb5c698bff0a4d73ee015230818faacc587b07d5
child 348151 0d33d81b075fc1cdc2c497efdd43346b89864604
push id39078
push userservo-vcs-sync@mozilla.com
push dateFri, 17 Mar 2017 12:53:34 +0000
treeherderautoland@1da2122f3597 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersKiChjang
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 #16010 - Properly coalesce whitespace when given a reference child (fixes #15979) (from nox:h5e); r=KiChjang Source-Repo: https://github.com/servo/servo Source-Revision: 32784c5fa8f30f007a45122dae5ae16d06d1733d
servo/components/script/dom/servoparser/mod.rs
--- a/servo/components/script/dom/servoparser/mod.rs
+++ b/servo/components/script/dom/servoparser/mod.rs
@@ -652,17 +652,22 @@ pub struct FragmentContext<'a> {
 
 #[allow(unrooted_must_root)]
 fn insert(parent: &Node, reference_child: Option<&Node>, child: NodeOrText<JS<Node>>) {
     match child {
         NodeOrText::AppendNode(n) => {
             parent.InsertBefore(&n, reference_child).unwrap();
         },
         NodeOrText::AppendText(t) => {
-            if let Some(text) = parent.GetLastChild().and_then(Root::downcast::<Text>) {
+            let text = reference_child
+                .and_then(Node::GetPreviousSibling)
+                .or_else(|| parent.GetLastChild())
+                .and_then(Root::downcast::<Text>);
+
+            if let Some(text) = text {
                 text.upcast::<CharacterData>().append_data(&t);
             } else {
                 let text = Text::new(String::from(t).into(), &parent.owner_doc());
                 parent.InsertBefore(text.upcast(), reference_child).unwrap();
             }
         },
     }
 }