jenkins-bot has submitted this change and it was merged.

Change subject: Fix crasher in DOMDiff: Lookup id in DOM only for <ref> data-mw
......................................................................


Fix crasher in DOMDiff: Lookup id in DOM only for <ref> data-mw

* 482083b48b88cc4bb53a61050438af0b8e0bf61e added specialized domdiff
  comparison for 'id' properties in data-mw.

  However, 'id' properties can show up for other reasons besides
  being element-ids added for <ref> bodies.

  Ex: {{Foobar|id=something}} will get a "id": {"wt": "something"}
  as part of the "params" property in data-mw. This key broke
  dom-diff.

* This patch adds safeguards to verify that the id property is
  used to look up a DOM element only if it shows up in a <ref>'s
  data-mw.

* Fixes rtselser and roundtrip-test crashers for enwiki:John_Carnell

Change-Id: I1b58412749a6d35986ba8ecb37d9a3d90e6a8857
---
M lib/mediawiki.DOMDiff.js
1 file changed, 21 insertions(+), 2 deletions(-)

Approvals:
  Arlolra: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/mediawiki.DOMDiff.js b/lib/mediawiki.DOMDiff.js
index 55663a2..6297720 100644
--- a/lib/mediawiki.DOMDiff.js
+++ b/lib/mediawiki.DOMDiff.js
@@ -67,6 +67,7 @@
  * - for id attributes, the DOM fragments are fetched and compared
  */
 DDP.dataMWEquals = function(nodeA, dmwA, nodeB, dmwB) {
+       var isRef = /\bmw:Extension\/ref\b/.test(nodeA.getAttribute("typeof"));
        var keysA = Object.keys(dmwA);
        var keysB = Object.keys(dmwB);
 
@@ -99,15 +100,33 @@
                        }
                } else if (vA.constructor !== vB.constructor) {
                        return false;
-               } else if (kA === 'id') {
+               } else if (kA === 'id' && isRef) {
                        // For <refs> in <references> the element id can refer 
to the
                        // global DOM, not the owner document DOM.
                        var htmlA = nodeA.ownerDocument.getElementById(vA)
                                || this.domA.getElementById(vA);
                        var htmlB = nodeB.ownerDocument.getElementById(vB)
                                || this.domB.getElementById(vB);
-                       if (!this.treeEquals(htmlA, htmlB, true)) {
+
+                       if (htmlA && htmlB && !this.treeEquals(htmlA, htmlB, 
true)) {
                                return false;
+                       } else if (!htmlA || !htmlB) {
+                               // Log error
+                               if (!htmlA) {
+                                       this.env.log("error",
+                                               "<ref> node with nonexistent 
body id in original DOM: ",
+                                               nodeA.outerHTML, "; id: ", 
JSON.stringify(vA));
+                               }
+                               if (!htmlB) {
+                                       this.env.log("error",
+                                               "<ref> node with nonexistent 
body id in edied DOM: ",
+                                               nodeB.outerHTML, "; id: ", 
JSON.stringify(vB));
+                               }
+
+                               // Fall back to default comparisons
+                               if (vA !== vB) {
+                                       return false;
+                               }
                        }
                } else if (kA === 'html') {
                        // For 'html' attributes, parse string and recursively 
compare DOM

-- 
To view, visit https://gerrit.wikimedia.org/r/212215
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1b58412749a6d35986ba8ecb37d9a3d90e6a8857
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: Cscott <canan...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to