jenkins-bot has submitted this change and it was merged. Change subject: (Bug 48570) Fix subtle selser bug handling separator-only nodes ......................................................................
(Bug 48570) Fix subtle selser bug handling separator-only nodes * When the original source for an element node whose content was entirely made up of separator text, selser duplicated the separator in leading and trailing separators. This manifested in the various bug reports around an extra space before links and colons (which introduces an <span> which exhibits this separator-only node behavior and causes the single-space duplication reported in the bug reports). * This patch also fixes 11 additional selser tests. Change-Id: Ibbc97e2eeb93fff56beb3fdc9cb2875ceb3e100b --- M js/lib/mediawiki.WikitextSerializer.js M js/tests/parserTests-blacklist.js 2 files changed, 25 insertions(+), 24 deletions(-) Approvals: GWicke: Looks good to me, approved jenkins-bot: Verified diff --git a/js/lib/mediawiki.WikitextSerializer.js b/js/lib/mediawiki.WikitextSerializer.js index 83bdd04..56b5ae1 100644 --- a/js/lib/mediawiki.WikitextSerializer.js +++ b/js/lib/mediawiki.WikitextSerializer.js @@ -455,7 +455,7 @@ if (sep && sep.match(/\n/)) { this.onSOL = true; } - if (this.debugging) { + if (this.serializer.debugging) { console.log(debugPrefix, JSON.stringify(sep)); } }, @@ -3946,24 +3946,28 @@ // Strip leading/trailing separators *ONLY IF* the previous/following // node will go through non-selser serialization. var src = state.getOrigSrc(dp.dsr[0], dp.dsr[1]), + out = src, stripLeading = !DU.isIndentPre(node) && DU.hasCurrentDiffMark(node.previousSibling, this.env), stripTrailing = DU.hasCurrentDiffMark(node.nextSibling, this.env), - leadingSepMatch = stripLeading ? src.match(/^((?:\s|<!--([^\-]|-(?!->))*-->)+)/) : null, - trailingSepMatch = stripTrailing ? src.match(/((?:\s|<!--([^\-]|-(?!->))*-->)+)$/) : null, - out = src, newSep = '', offset = 0; - if (leadingSepMatch) { - state.sep.src = (state.sep.src || '') + leadingSepMatch[0]; - offset = leadingSepMatch[0].length; - out = out.substring(offset); - dp.dsr[0] += offset; + if (stripLeading) { + var leadingSepMatch = out.match(/^((?:\s|<!--([^\-]|-(?!->))*-->)+)/); + if (leadingSepMatch) { + state.sep.src = (state.sep.src || '') + leadingSepMatch[0]; + offset = leadingSepMatch[0].length; + out = out.substring(offset); + dp.dsr[0] += offset; + } } - if (trailingSepMatch) { - newSep = trailingSepMatch[0]; - out = out.substring(0, trailingSepMatch.index - offset); - dp.dsr[1] -= trailingSepMatch.index; + if (stripTrailing) { + var trailingSepMatch = out.match(/((?:\s|<!--([^\-]|-(?!->))*-->)+)$/); + if (trailingSepMatch) { + newSep = trailingSepMatch[0]; + out = out.substring(0, trailingSepMatch.index); + dp.dsr[1] -= trailingSepMatch.index; + } } state.currNodeUnmodified = true; @@ -4032,6 +4036,10 @@ break; case node.TEXT_NODE: + if (state.selserMode) { + this.trace("TEXT: ", node.nodeValue); + } + if (!this.handleSeparatorText(node, state)) { // Text is not just whitespace prev = this._getPrevSeparatorElement(node, state); @@ -4052,6 +4060,10 @@ } break; case node.COMMENT_NODE: + if (state.selserMode) { + this.trace("COMMENT: ", node.nodeValue); + } + // delay the newline creation until after the comment if (!this.handleSeparatorText(node, state)) { cb(commentWT(node.nodeValue), node); diff --git a/js/tests/parserTests-blacklist.js b/js/tests/parserTests-blacklist.js index f9a6b49..79dbcb0 100644 --- a/js/tests/parserTests-blacklist.js +++ b/js/tests/parserTests-blacklist.js @@ -2493,8 +2493,6 @@ add("selser", "HTML-pre: 1. embedded newlines [0,4,0,2,0,0,1]"); add("selser", "HTML-pre: 1. embedded newlines [0,0,[2],3,0,4,4]"); add("selser", "HTML-pre: 1. embedded newlines [0,3,[4],3,0,3,[2]]"); -add("selser", "Simple definition [[[3,2],3]]"); -add("selser", "Definition list with URL link [[[4,2,2],4]]"); add("selser", "Definition list with URL link [[1,0]]"); add("selser", "Definition list with URL link [[1,[3]]]"); add("selser", "Definition lists: self-closed tag [2]"); @@ -2503,10 +2501,8 @@ add("selser", "Definition lists: self-closed tag [[[4,0,2,0],4]]"); add("selser", "Definition lists: self-closed tag [[[2,2,0,3],[3]]]"); add("selser", "Definition lists: self-closed tag [[[0,0,0,[3]],0]]"); -add("selser", "Definition lists: self-closed tag [[[0,1,4,[2]],2]]"); add("selser", "Definition lists: self-closed tag [[[0,0,0,1],0]]"); add("selser", "Definition lists: self-closed tag [[[3,0,0,1],2]]"); -add("selser", "Definition lists: self-closed tag [[[2,1,3,0],1]]"); add("selser", "Definition lists: self-closed tag [[2,3]]"); add("selser", "Definition lists: self-closed tag [[[0,0,2,[4]],3]]"); add("selser", "Definition lists: self-closed tag [[1,0]]"); @@ -2575,7 +2571,6 @@ add("selser", "Definition Lists: Mixed Lists: Test 3 [[[[[[1]]]]]]"); add("selser", "Definition Lists: Mixed Lists: Test 4 [[[2]]]"); add("selser", "Definition Lists: Mixed Lists: Test 4 [[[[[3,[4]],1,0,0,4]]]]"); -add("selser", "Definition Lists: Mixed Lists: Test 4 [[[[4,[4],2,1,2]]]]"); add("selser", "Definition Lists: Mixed Lists: Test 4 [[1]]"); add("selser", "Definition Lists: Mixed Lists: Test 4 [[[1]]]"); add("selser", "Definition Lists: Mixed Lists: Test 5 [[[1]]]"); @@ -2605,16 +2600,13 @@ add("selser", "Definition Lists: Mixed Lists: Test 8 [[[1,0,3]]]"); add("selser", "Definition Lists: Mixed Lists: Test 8 [[[[[2]],4,2]]]"); add("selser", "Definition Lists: Mixed Lists: Test 9 [[1]]"); -add("selser", "Definition Lists: Mixed Lists: Test 9 [[[[[3,2],2]]]]"); add("selser", "Definition Lists: Mixed Lists: Test 9 [[[[2,0]]]]"); add("selser", "Definition Lists: Mixed Lists: Test 9 [[[1]]]"); -add("selser", "Definition Lists: Mixed Lists: Test 9 [[[[1,4]]]]"); add("selser", "Definition Lists: Mixed Lists: Test 10 [[1]]"); add("selser", "Definition Lists: Mixed Lists: Test 10 [[[[[[2,0]]]]]]"); add("selser", "Definition Lists: Mixed Lists: Test 10 [[[1]]]"); add("selser", "Definition Lists: Mixed Lists: Test 10 [[[[1]]]]"); add("selser", "Definition Lists: Mixed Lists: Test 10 [[[[[[2,[3]]]]]]]"); -add("selser", "Definition Lists: Mixed Lists: Test 10 [[[[[[1,3]]]]]]"); add("selser", "Definition Lists: Mixed Lists: Test 11 (parsoid) [[[1]]]"); add("selser", "Definition Lists: Mixed Lists: Test 11 (parsoid) [[[2]]]"); add("selser", "Definition Lists: Mixed Lists: Test 11 (parsoid) [[1]]"); @@ -3502,7 +3494,6 @@ add("selser", "Non-transclusion because of too many up levels [[4]]"); add("selser", "Non-transclusion because of too many up levels [[3]]"); add("selser", "Non-transclusion because of too many up levels [[2]]"); -add("selser", "Definition list code coverage [[1,1,4,[0,3],4,0,2,0]]"); add("selser", "Don't fall for the self-closing div [[4]]"); add("selser", "Don't fall for the self-closing div [[3]]"); add("selser", "Don't fall for the self-closing div [2]"); @@ -3775,8 +3766,6 @@ add("selser", "1. Quotes inside <b> and <i> [[3,0,0,0,0,4,4,0,3,1,3,0,3,1,3,4,4,4,0,3,4,3,2,3,0,0,3,4,0,4,0,1,0,0,0,[3],0,0]]"); add("selser", "1. Quotes inside <b> and <i> [[2,0,[4],0,[2],2,[2],3,0,1,3,1,0,1,0,[[3],[[4]],4],3,4,1,2,0,3,0,2,4,1,4,3,0,3,4,3,3,4,0,3,0,2]]"); add("selser", "1. Quotes inside <b> and <i> [[[1],0,4,2,4,0,0,0,3,[1],4,1,3,0,0,1,3,0,0,0,[4],3,1,3,0,1,4,3,2,3,4,1,1,4,4,0,4,0]]"); -add("selser", "(Bug 52035) Nowiki-escaping should not get tripped by \" :\" in text [1]"); -add("selser", "(Bug 52035) Nowiki-escaping should not get tripped by \" :\" in text [[2,2,0]]"); add("selser", "HTML tag with broken attribute value quoting [1]"); add("selser", "HTML tag with broken attribute value quoting [2]"); add("selser", "HTML tag with broken attribute value quoting [[2]]"); -- To view, visit https://gerrit.wikimedia.org/r/84701 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibbc97e2eeb93fff56beb3fdc9cb2875ceb3e100b Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Parsoid Gerrit-Branch: master Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: GWicke <gwi...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits