jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/386016 )
Change subject: Linter: Add tidy-font-bug category
......................................................................
Linter: Add tidy-font-bug category
* This identifies breakage identified in T25467.
Clearly, Tidy does some strange things sometimes.
* Added a bunch of mocha tests to verify this
expectation.
Bug: T25467
Bug: T176568
Change-Id: I7510ad39172b4025a79bc6f3f26eb265587c8d8c
---
M lib/wt2html/pp/handlers/linter.js
M tests/mocha/linter.js
2 files changed, 114 insertions(+), 1 deletion(-)
Approvals:
jenkins-bot: Verified
Arlolra: Looks good to me, approved
diff --git a/lib/wt2html/pp/handlers/linter.js
b/lib/wt2html/pp/handlers/linter.js
index 87d1ba0..22712e7 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -443,8 +443,9 @@
obsoleteTagsRE = new RegExp('^(' + elts.join('|') + ')$');
}
+ var templateInfo;
if (!(dp.autoInsertedStart && dp.autoInsertedEnd) &&
obsoleteTagsRE.test(c.nodeName)) {
- var templateInfo = findEnclosingTemplateName(env, tplInfo);
+ templateInfo = findEnclosingTemplateName(env, tplInfo);
var lintObj = {
dsr: findLintDSR(templateInfo, tplInfo, dp.dsr),
templateInfo: templateInfo,
@@ -452,6 +453,66 @@
};
env.log('lint/obsolete-tag', lintObj);
}
+
+ if (c.nodeName === 'FONT' && c.getAttribute('color')) {
+ /* ----------------------------------------------------------
+ * Tidy migrates <font> into the link in these cases
+ * <font>[[Foo]]</font>
+ * <font>[[Foo]]l</font> (link-trail)
+ * <font><!--boo-->[[Foo]]</font>
+ * <font>__NOTOC__[[Foo]]</font>
+ * <font>[[Category:Foo]][[Foo]]</font>
+ * <font>{{1x|[[Foo]]}}</font>
+ *
+ * Tidy does not migrate <font> into the link in these cases
+ * <font> [[Foo]]</font>
+ * <font>[[Foo]] </font>
+ * <font>[[Foo]]L</font> (not a link-trail)
+ * <font>[[Foo]][[Bar]]</font>
+ * <font>[[Foo]][[Bar]]</font>
+ *
+ * <font> is special.
+ * This behavior is not seen with other formatting tags.
+ *
+ * Remex/parsoid won't do any of this.
+ * This difference in behavior only matters when the font tag
+ * specifies a link colour because the link no longer renders
+ * as blue/red but in the font-specified colour.
+ * ---------------------------------------------------------- */
+ var tidyFontBug = true;
+ var haveLink = false;
+ for (var n = c.firstChild; n; n = n.nextSibling) {
+ if (!DU.isComment(n) &&
+ n.nodeName !== 'A' &&
+ n.nodeName !== 'FIGURE' &&
+ !(n.nodeName === 'SPAN' &&
/\bmw:Image\b/.test(n.getAttribute('typeof'))) &&
+ !DU.isBehaviorSwitch(env, n) &&
+ !DU.isSolTransparentLink(n) &&
+ !(n.nodeName === 'META' &&
Util.TPL_META_TYPE_REGEXP.test(n.getAttribute('typeof')))
+ ) {
+ tidyFontBug = false;
+ break;
+ }
+
+ if (n.nodeName === 'A' || n.nodeName === 'FIGURE') {
+ if (!haveLink) {
+ haveLink = true;
+ } else {
+ tidyFontBug = false;
+ break;
+ }
+ }
+ }
+
+ if (tidyFontBug) {
+ templateInfo = findEnclosingTemplateName(env, tplInfo);
+ env.log('lint/tidy-font-bug', {
+ dsr: findLintDSR(templateInfo, tplInfo, dp.dsr),
+ templateInfo: templateInfo,
+ params: { name: 'font' },
+ });
+ }
+ }
}
/*
diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js
index 33d68df..d710ede 100644
--- a/tests/mocha/linter.js
+++ b/tests/mocha/linter.js
@@ -745,4 +745,56 @@
});
});
});
+ describe('TIDY FONT BUG', function() {
+ var wtLines = [
+ "<font color='green'>[[Foo]]</font>",
+ "<font color='green'>[[Category:Boo]][[Foo]]</font>",
+ "<font color='green'>__NOTOC__[[Foo]]</font>",
+ "<font color='green'><!--boo-->[[Foo]]</font>",
+ "<font color='green'>[[Foo|bar]]</font>",
+ "<font color='green'>[[Foo|''bar'']]</font>",
+ "<font color='green'>[[Foo|''bar'' and boo]]</font>",
+ "<font color='green'>[[File:Foo.jpg|some
caption]]</font>",
+ "<font color='green'>[[File:Foo.jpg|thumb|128px|some
caption]]</font>",
+ "<font color='green'>[[Foo]]l</font>",
+ "<font color='green'>{{1x|[[Foo]]}}</font>",
+ ];
+ it('should flag Tidy font fixups accurately when color
attribute is present', function() {
+ return
parseWT(wtLines.join('\n')).then(function(result) {
+ var n = wtLines.length;
+ result.should.have.length(2 * n);
+ for (var i = 0; i < 2 * n; i += 2) {
+
result[i].should.have.a.property("type", "obsolete-tag");
+ result[i +
1].should.have.a.property("type", "tidy-font-bug");
+ }
+ });
+ });
+ it('should not flag Tidy font fixups when color attribute is
absent', function() {
+ return parseWT(wtLines.join('\n').replace(/
color='green'/g, '')).then(function(result) {
+ var n = wtLines.length;
+ result.should.have.length(n);
+ for (var i = 0; i < n; i += 1) {
+
result[i].should.have.a.property("type", "obsolete-tag");
+ }
+ });
+ });
+ var wtLines2 = [
+ "<font color='green'>[[Foo]][[Bar]]</font>",
+ "<font color='green'> [[Foo]]</font>",
+ "<font color='green'>[[Foo]] </font>",
+ "<font color='green'>[[Foo]]D</font>",
+ "<font color='green'>''[[Foo|bar]]''</font>",
+ "<font color='green'><span>[[Foo|bar]]</span></font>",
+ "<font color='green'><div>[[Foo|bar]]</div></font>",
+ ];
+ it('should not flag Tidy font fixups when Tidy does not do the
fixups', function() {
+ return
parseWT(wtLines2.join('\n')).then(function(result) {
+ var n = wtLines2.length;
+ result.should.have.length(n);
+ for (var i = 0; i < n; i += 1) {
+
result[i].should.have.a.property("type", "obsolete-tag");
+ }
+ });
+ });
+ });
});
--
To view, visit https://gerrit.wikimedia.org/r/386016
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7510ad39172b4025a79bc6f3f26eb265587c8d8c
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Sbailey <[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