Subramanya Sastry has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398518 )

Change subject: Linter: Suppress false positives for 
multiple-unclosed-formatting-tags
......................................................................

Linter: Suppress false positives for multiple-unclosed-formatting-tags

* Unclosed tags in tables don't leak out of the table in the HTML5
  tree building algorithm. So, those should be ignored for the purpose
  of detecting multiple unclosed formatting tags.

* There are of course edge cases here that we are going to conveniently
  ignore. For example, if the multiple unclosed tags are in the same
  table cell, that should trigger the check, but not sure it is worth
  the complexity.

  There are probably other edge cases where Tidy and HTML5 parsing
  will do things differently, but I think this is enough for now.
  At this rate, before long, we'll be running Tidy's fixup code in Parsoid.

* New tests added to spec this behavior.

* Verified on enwiki:Papa_Dee

Change-Id: Ie979ce0940a1613d5a4203ff75358dbf91f2535e
---
M lib/wt2html/pp/handlers/linter.js
M tests/mocha/linter.js
2 files changed, 23 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/18/398518/1

diff --git a/lib/wt2html/pp/handlers/linter.js 
b/lib/wt2html/pp/handlers/linter.js
index a752413..caa1891 100644
--- a/lib/wt2html/pp/handlers/linter.js
+++ b/lib/wt2html/pp/handlers/linter.js
@@ -386,6 +386,7 @@
                                        adjDp.tmp.linted = true;
                                        env.log('lint/misnested-tag', lintObj);
                                } else if (!endTagOptional(c)) {
+                                       lintObj.params.inTable = 
DU.hasAncestorOfName(c, 'TABLE');
                                        env.log('lint/missing-end-tag', 
lintObj);
                                        if 
(Consts.HTML.FormattingTags.has(c.nodeName) && matchedOpenTagPairExists(c, dp)) 
{
                                                
env.log('lint/multiple-unclosed-formatting-tags', lintObj);
@@ -843,7 +844,8 @@
        };
        var multiUnclosedTagName = null;
        lints.find(function(item) {
-               if (item.type === 'missing-end-tag') {
+               // Unclosed tags in tables don't leak out of the table
+               if (item.type === 'missing-end-tag' && !item.params.inTable) {
                        if (item.params.name === 'small' || item.params.name 
=== 'big') {
                                var tagName = item.params.name;
                                if (!firstUnclosedTag[tagName]) {
diff --git a/tests/mocha/linter.js b/tests/mocha/linter.js
index 4ed63ac..f1679db 100644
--- a/tests/mocha/linter.js
+++ b/tests/mocha/linter.js
@@ -40,6 +40,14 @@
                });
        };
 
+       var noLintsOfThisType = function(wt, type) {
+               return parseWT(wt).then(function(result) {
+                       result.forEach(function(r) {
+                               r.should.not.have.a.property("type", type);
+                       });
+               });
+       };
+
        describe('#Issues', function() {
                it('should not lint any issues', function() {
                        return expectEmptyResults('foo');
@@ -833,6 +841,16 @@
                                result[4].params.should.have.a.property("name", 
"small");
                        });
                });
+               it('should ignore unclosed small tags in tables', function() {
+                       noLintsOfThisType('{|\n|<small>a\n|<small>b\n|}', 
"multiple-unclosed-formatting-tags");
+               });
+               it('should ignore unclosed small tags in tables but detect 
those outside it', function() {
+                       return 
parseWT('<small>x\n{|\n|<small>a\n|<small>b\n|}\n<small>y').then(function(result)
 {
+                               result.should.have.length(5);
+                               result[4].should.have.a.property("type", 
"multiple-unclosed-formatting-tags");
+                               result[4].params.should.have.a.property("name", 
"small");
+                       });
+               });
                it("should detect Tidy's smart auto-fixup of paired unclosed 
formatting tags", function() {
                        return parseWT('<b>foo<b>\n<code>foo <span>x</span> 
bar<code>').then(function(result) {
                                result.should.have.length(6);
@@ -845,18 +863,10 @@
                        });
                });
                it("should not flag Tidy's smart auto-fixup of paired unclosed 
formatting tags where Tidy won't do it", function() {
-                       return parseWT('<b>foo <b>\n<code>foo <span>x</span> 
<!--comment--><code>').then(function(result) {
-                               result.forEach(function(r) {
-                                       r.should.not.have.a.property("type", 
"multiple-unclosed-formatting-tags");
-                               });
-                       });
+                       noLintsOfThisType('<b>foo <b>\n<code>foo <span>x</span> 
<!--comment--><code>', "multiple-unclosed-formatting-tags");
                });
                it("should not flag Tidy's smart auto-fixup of paired unclosed 
tags for non-formatting tags", function() {
-                       return parseWT('<span>foo<span>\n<div>foo 
<span>x</span> bar<div>').then(function(result) {
-                               result.forEach(function(r) {
-                                       r.should.not.have.a.property("type", 
"multiple-unclosed-formatting-tags");
-                               });
-                       });
+                       noLintsOfThisType('<span>foo<span>\n<div>foo 
<span>x</span> bar<div>', "multiple-unclosed-formatting-tags");
                });
        });
        describe('MISC TIDY REPLACEMENT ISSUES', function() {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie979ce0940a1613d5a4203ff75358dbf91f2535e
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

Reply via email to