Subramanya Sastry has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/393921 )
Change subject: Fix crasher in getDSR in section wrapping code
......................................................................
Fix crasher in getDSR in section wrapping code
When resolving section-template conflicts, we try to expand the range
of template ranges to includes all content within a section. As part
of that, we need to update the DSR and traverse the non-template
content to compute offsets. When non-templated content only includes
text and comment nodes, we hit templated content. At that point, we
should get the baseline DSR info from the template wrapper. Otherwise,
if we query the last node of the templated content region for DSR
info, we get an undefined value.
This should fix crashers found in RT testing.
I left behind section counters added during debugging.
Change-Id: I8eb21996b9e7bcb856322a7bdfa6eec5882303a0
---
M lib/wt2html/pp/processors/wrapSections.js
1 file changed, 8 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/21/393921/1
diff --git a/lib/wt2html/pp/processors/wrapSections.js
b/lib/wt2html/pp/processors/wrapSections.js
index 0ac5b54..d2fb077 100644
--- a/lib/wt2html/pp/processors/wrapSections.js
+++ b/lib/wt2html/pp/processors/wrapSections.js
@@ -18,9 +18,9 @@
*/
var section = {
level: newLevel,
+ id: state.count++,
container: state.doc.createElement('section'),
};
-
/* Step 1. Get section stack to the right nesting level
* 1a. Pop stack till we have a higher-level section.
@@ -172,9 +172,9 @@
return highestSectionLevel;
}
-function getDSR(node, start) {
+function getDSR(tplInfo, node, start) {
if (node.nodeName !== 'SECTION') {
- var dsr = DU.getDataParsoid(node).dsr;
+ var dsr = DU.getDataParsoid(node).dsr ||
DU.getDataParsoid(tplInfo.first).dsr;
return start ? dsr[0] : dsr[1];
}
@@ -184,7 +184,7 @@
if (!DU.isElt(c)) {
offset += c.textContent.length;
} else {
- return getDSR(c, start) + (start ? -offset : offset);
+ return getDSR(tplInfo, c, start) + (start ? -offset :
offset);
}
c = start ? c.nextSibling : c.previousSibling;
}
@@ -215,7 +215,7 @@
s2 = tplInfo.lastSection.container;
if (tplInfo.last.nextSibling) {
// Append the content of the section after the
last node to data-mw.parts
- var newTplEndOffset = getDSR(s2, false); //
will succeed because it traverses non-tpl content
+ var newTplEndOffset = getDSR(tplInfo, s2,
false); // will succeed because it traverses non-tpl content
tplDsr = DU.getDataParsoid(tplInfo.first).dsr;
var tplEndOffset = tplDsr[1];
dmw = DU.getDataMw(tplInfo.first);
@@ -254,8 +254,8 @@
}
// Update transclusion info
- var dsr1 = getDSR(newS1, true); // will succeed because
it traverses non-tpl content
- var dsr2 = getDSR(newS2, false); // will succeed
because it traverses non-tpl content
+ var dsr1 = getDSR(tplInfo, newS1, true); // will
succeed because it traverses non-tpl content
+ var dsr2 = getDSR(tplInfo, newS2, false); // will
succeed because it traverses non-tpl content
var tplDP = DU.getDataParsoid(tplInfo.first);
tplDsr = tplDP.dsr;
dmw = Util.clone(DU.getDataMw(tplInfo.first));
@@ -289,6 +289,7 @@
// Global state
var state = {
env: env,
+ count: 0,
doc: doc,
rootNode: rootNode,
sectionNumber: 0,
--
To view, visit https://gerrit.wikimedia.org/r/393921
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8eb21996b9e7bcb856322a7bdfa6eec5882303a0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits