jenkins-bot has submitted this change and it was merged.
Change subject: Stop working on cloned nodes in parserTests
......................................................................
Stop working on cloned nodes in parserTests
* This cloning is only present in parserTests.
* It can lead to subtle breakage where DOM methods return elements
from the original, un-cloned node. For example, in the cite
extension, the call to ownerDocument.getElementById
* A test is added to demonstrate this broken behaviour in the test
harness. It highlights the fact that the returned element will be the
unedited one from before cloning. It doesn't pass on master.
* The cloning that's removed from convertWt2Html (added in 8faefac1)
hasn't been necessary for a while. A new document is created when
the parser pipeline is reset.
Change-Id: Ie1bcc6086bcb65a27d2168355c31e7b956cd01dc
---
M bin/parserTests.js
M tests/parserTests.txt
2 files changed, 27 insertions(+), 15 deletions(-)
Approvals:
Subramanya Sastry: Looks good to me, approved
jenkins-bot: Verified
diff --git a/bin/parserTests.js b/bin/parserTests.js
index 410565c..ad0ab3a 100755
--- a/bin/parserTests.js
+++ b/bin/parserTests.js
@@ -425,7 +425,7 @@
// FIXME: All tests share an env.
// => we need to initialize this each time over here.
this.env.page.dom = item.cachedBODY;
- this.env.page.editedDoc = item.cachedBODY.ownerDoc;
+ this.env.page.editedDoc = body.ownerDocument;
}
if (mode === 'selser') {
// console.warn("--> selsering: " + body.outerHTML);
@@ -861,16 +861,12 @@
* @param {string} wikitext
* @param {Function} processHtmlCB
* @param {Error|null} processHtmlCB.err
- * @param {Node|null} processHtmlCB.doc
+ * @param {Node|null} processHtmlCB.body
*/
ParserTests.prototype.convertWt2Html = function(mode, wikitext, processHtmlCB)
{
this.env.setPageSrcInfo(wikitext);
this.parserPipeline.once('document', function(doc) {
- // processHtmlCB can be asynchronous, so deep-clone
- // document before invoking it. (the parser pipeline
- // will attempt to reuse the document after this
- // event is emitted)
- processHtmlCB(null, doc.body.cloneNode(true));
+ processHtmlCB(null, doc.body);
});
this.parserPipeline.processToplevelDoc(wikitext);
};
@@ -960,7 +956,8 @@
// so we can maybe skip them later
testTasks.push(function(body, cb) {
// Cache parsed HTML
- item.cachedBODY =
DU.parseHTML(DU.serializeNode(body).str).body;
+ item.cachedBODYstr = DU.serializeNode(body).str;
+ item.cachedBODY =
DU.parseHTML(item.cachedBODYstr).body;
// - In wt2html mode, pass through original DOM
// so that it is serialized just once.
@@ -970,12 +967,12 @@
if (mode === "wt2html") {
cb(null, body);
} else {
- cb(null,
item.cachedBODY.cloneNode(true));
+ cb(null,
DU.parseHTML(item.cachedBODYstr).body);
}
});
} else {
testTasks.push(function(cb) {
- cb(null, item.cachedBODY.cloneNode(true));
+ cb(null, DU.parseHTML(item.cachedBODYstr).body);
});
}
}
@@ -1844,11 +1841,6 @@
} else {
item.selserChangeTrees[changesIndex] = newitem.changes;
}
-
- // Push the caches
forward!
- item.cachedBODY =
newitem.cachedBODY;
-
item.cachedNormalizedHTML = newitem.cachedNormalizedHTML;
-
setImmediate(cb, err);
}.bind(this));
}
@@ -1918,6 +1910,7 @@
// Reset the cached results for the new case.
// All test modes happen in a single run of processCase.
+ item.cachedBODYstr = null;
item.cachedBODY = null;
item.cachedNormalizedHTML = null;
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 691113d..543012c 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -7092,6 +7092,25 @@
|}
!! end
+!! test
+Testing serialization after deletion in references
+!! options
+parsoid={
+ "modes": ["wt2wt"],
+ "changes": [
+ ["#x", "remove"]
+ ]
+}
+!! wikitext
+hi <ref><div id="x">ho</div></ref>
+
+<references />
+!! wikitext/edited
+hi <ref></ref>
+
+<references />
+!! end
+
!!test
Testing serialization after deletion of table cells
!!options
--
To view, visit https://gerrit.wikimedia.org/r/280613
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie1bcc6086bcb65a27d2168355c31e7b956cd01dc
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits