Subramanya Sastry has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/346904 )
Change subject: Address edge case in DSR code that affects lint output in some
cases
......................................................................
Address edge case in DSR code that affects lint output in some cases
eccca398 added some DSR correction code for b/i tag misnesting
by (correctly) swallowing the DSR width of the stripped meta tag.
However, this also causes the stripped-elt meta tag itself to get
its DSR corrected to zero-width because of the forward pass.
This is not a problem normally since the meta tag will get stripped.
However, this trips up the linter stripped-tag DSR values for snippets
with i/b tags in them. It emits zero-width DSR for them. To prevent
this, we record the original DSR in a dp.tmp and utilize it in the
linter.
Added a new test case that passes with this patch and fails without.
Change-Id: Ie15c5311957995bf4fdbb97771e927b6ac39ba9e
---
M lib/wt2html/pp/handlers/linter.js
M lib/wt2html/pp/processors/computeDSR.js
M tests/mocha/linter.js
3 files changed, 21 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/04/346904/1
diff --git a/lib/wt2html/pp/handlers/linter.js
b/lib/wt2html/pp/handlers/linter.js
index b83ec0f..a07f329 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -60,6 +60,12 @@
templateInfo = {
name: DU.findEnclosingTemplateName(tplInfo),
};
+ } else if (dp.tmp.origDSR) {
+ // During DSR computation, stripped meta tags
+ // surrender their width to its previous sibling.
+ // We record the original DSR in the tmp attribute
+ // for that reason.
+ dsr = dp.tmp.origDSR;
}
if (DU.hasNodeName(c, 'meta')) {
diff --git a/lib/wt2html/pp/processors/computeDSR.js
b/lib/wt2html/pp/processors/computeDSR.js
index 038cf49..3b0abb8 100644
--- a/lib/wt2html/pp/processors/computeDSR.js
+++ b/lib/wt2html/pp/processors/computeDSR.js
@@ -241,6 +241,14 @@
correction = ndp.src.length;
ce += correction;
dsrCorrection = correction;
+
+ // Record original DSR for the
meta tag
+ // since it will now get
corrected to zero width
+ // since child acquires its
width.
+ if (!ndp.tmp) {
+ ndp.tmp = {};
+ }
+ ndp.tmp.origDSR = [ndp.dsr[0],
ndp.dsr[1], null, null];
}
}
}
diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js
index 7c7dc89..6afa1ad 100644
--- a/tests/mocha/linter.js
+++ b/tests/mocha/linter.js
@@ -61,6 +61,13 @@
result[0].dsr.should.deep.equal([ 0, 27, null,
null ]);
});
});
+ it('should lint stripped tags correctly in misnested tag
situations', function() {
+ return parseWT('<b><i>a</b></i>').then(function(result)
{
+ result.should.have.length(2);
+ result[1].should.have.a.property("type",
"stripped-tag");
+ result[1].dsr.should.deep.equal([ 11, 15, null,
null ]);
+ });
+ });
it('should lint obsolete tags correctly', function() {
return parseWT('<tt>foo</tt>bar').then(function(result)
{
result.should.have.length(1);
--
To view, visit https://gerrit.wikimedia.org/r/346904
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie15c5311957995bf4fdbb97771e927b6ac39ba9e
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