jenkins-bot has submitted this change and it was merged.

Change subject: Followup on a8ee9bf5: Normalize newlines around new content only
......................................................................


Followup on a8ee9bf5: Normalize newlines around new content only

* Since it looks like the extra newlines might be used as
  a stylistic practice in wikitext for tables, use the normalized
  single-newline form only around new content.

  Discovered via rt-testing.

* Selser changes seem expected.

Change-Id: I615d6dc3399a0bef5707463ce6188ff36b247185
---
M lib/html2wt/DOMHandlers.js
M tests/parserTests-blacklist.js
2 files changed, 37 insertions(+), 24 deletions(-)

Approvals:
  Arlolra: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/html2wt/DOMHandlers.js b/lib/html2wt/DOMHandlers.js
index d4d6de6..a992233 100644
--- a/lib/html2wt/DOMHandlers.js
+++ b/lib/html2wt/DOMHandlers.js
@@ -561,6 +561,10 @@
        }
 }
 
+function maxNLsInTable(node, origNode) {
+       return DU.isNewElt(node) || DU.isNewElt(origNode) ? 1 : 2;
+}
+
 /**
  * A map of `domHandler`s keyed on nodeNames.
  *
@@ -699,8 +703,12 @@
                                        return { min: 0, max: 2 };
                                }
                        },
-                       firstChild: id({ min: 1, max: 1 }),
-                       lastChild: id({ min: 1, max: 1 }),
+                       firstChild: function(node, otherNode) {
+                               return { min: 1, max: maxNLsInTable(node, 
otherNode) };
+                       },
+                       lastChild: function(node, otherNode) {
+                               return { min: 1, max: maxNLsInTable(node, 
otherNode) };
+                       },
                },
        },
        tbody: justChildren,
@@ -727,13 +735,13 @@
                sepnls: {
                        before: function(node, otherNode) {
                                if (trWikitextNeeded(node, 
DU.getDataParsoid(node))) {
-                                       return { min: 1, max: 1 };
+                                       return { min: 1, max: 
maxNLsInTable(node, otherNode) };
                                } else {
-                                       return { min: 0, max: 1 };
+                                       return { min: 0, max: 
maxNLsInTable(node, otherNode) };
                                }
                        },
                        after: function(node, otherNode) {
-                               return { min: 0, max: 1 };
+                               return { min: 0, max: maxNLsInTable(node, 
otherNode) };
                        },
                },
        },
@@ -760,17 +768,17 @@
                                if (otherNode.nodeName === 'TH' &&
                                                DU.getDataParsoid(node).stx_v 
=== 'row') {
                                        // force single line
-                                       return { min: 0, max: 1 };
+                                       return { min: 0, max: 
maxNLsInTable(node, otherNode) };
                                } else {
-                                       return { min: 1, max: 1 };
+                                       return { min: 1, max: 
maxNLsInTable(node, otherNode) };
                                }
                        },
                        after: function(node, otherNode) {
                                if (otherNode.nodeName === 'TD') {
                                        // Force a newline break
-                                       return { min: 1, max: 1 };
+                                       return { min: 1, max: 
maxNLsInTable(node, otherNode) };
                                } else {
-                                       return { min: 0, max: 1 };
+                                       return { min: 0, max: 
maxNLsInTable(node, otherNode) };
                                }
                        },
                },
@@ -799,12 +807,14 @@
                                if (otherNode.nodeName === 'TD' &&
                                                DU.getDataParsoid(node).stx_v 
=== 'row') {
                                        // force single line
-                                       return { min: 0, max: 1 };
+                                       return { min: 0, max: 
maxNLsInTable(node, otherNode) };
                                } else {
-                                       return { min: 1, max: 1 };
+                                       return { min: 1, max: 
maxNLsInTable(node, otherNode) };
                                }
                        },
-                       after: id({ min: 0, max: 1 }),
+                       after: function(node, otherNode) {
+                               return { min: 0, max: maxNLsInTable(node, 
otherNode) };
+                       },
                },
        },
        caption: {
@@ -820,9 +830,12 @@
                sepnls: {
                        before: function(node, otherNode) {
                                return otherNode.nodeName !== 'TABLE' ?
-                                       { min: 1, max: 1 } : { min: 0, max: 1 };
+                                       { min: 1, max: maxNLsInTable(node, 
otherNode) } :
+                                       { min: 0, max: maxNLsInTable(node, 
otherNode) };
                        },
-                       after: id({ min: 1, max: 1 }),
+                       after: function(node, otherNode) {
+                               return { min: 1, max: maxNLsInTable(node, 
otherNode) };
+                       },
                },
        },
        // Insert the text handler here too?
diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js
index aa3fa2d..19c9f9a 100644
--- a/tests/parserTests-blacklist.js
+++ b/tests/parserTests-blacklist.js
@@ -358,7 +358,7 @@
 add("wt2wt", "Fuzz testing: Parser16", "{|\n!https://||||||\n|}");
 add("wt2wt", "Fuzz testing: Parser21", "{|\n! irc://{{ftp://a\"; 
onmouseover=\"alert('hello world');\"\n|\n|}");
 add("wt2wt", "Fuzz testing: Parser22", "http://===r:::https://b\n\n{|\n|}");
-add("wt2wt", "Fuzz testing: Parser24", "<nowiki>{{{|</nowiki>\n<u class=\"|\" 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" />\n\nMOVE YOUR MOUSE CURSOR 
OVER THIS TEXT\n{|\n|\n|}");
+add("wt2wt", "Fuzz testing: Parser24", "<nowiki>{{{|</nowiki>\n<u class=\"|\" 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" />\n\nMOVE YOUR MOUSE CURSOR 
OVER THIS TEXT\n{|\n\n|\n|}");
 add("wt2wt", "Inline wiki vs wiki block nesting", "'''Bold paragraph'''\n\nNew 
wiki paragraph\n");
 add("wt2wt", "Mixing markup for italics and bold", 
"'<nowiki/>''bold'<nowiki/>'''''bold''bolditalics'''''\n");
 add("wt2wt", "Illegal character references (T106578)", "; Null: &#00;\n; FF: 
&#xC;\n; CR: &#x0A;\n; Control (low): &#8;\n; Control (high): &#x7F; &#x9F;\n; 
Surrogate: &#xD83D;&#xDCA9;\n; This is an okay astral character: &#x1F4A9;");
@@ -1726,7 +1726,7 @@
 add("selser", "1. Table tag in SOL posn. should get reparsed correctly with 
valid TSR [0,[4,[3,0]]]", "{{echo|}}{| width = 
'100%'<!--4w5gtskk09ou5wmi-->\n|}");
 add("selser", "1. Table tag in SOL posn. should get reparsed correctly with 
valid TSR [0,2]", "{{echo|}}nbv262u96o3cjtt9\n{| width = '100%'\n|foo\n|}");
 add("selser", "1. Table tag in SOL posn. should get reparsed correctly with 
valid TSR [0,[0,1]]", "{{echo|}}{| width = '100%'\n|foo\n|}");
-add("selser", "1. Table tag in SOL posn. should get reparsed correctly with 
valid TSR [0,[0,[[3],0]]]", "{{echo|}}{| width = '100%'\n|}");
+add("selser", "1. Table tag in SOL posn. should get reparsed correctly with 
valid TSR [0,[0,[[3],0]]]", "{{echo|}}{| width = '100%'\n\n|}");
 add("selser", "1. Table tag in SOL posn. should get reparsed correctly with 
valid TSR [0,[0,[1,4]]]", "{{echo|}}{| width = 
'100%'\n|foo<!--ls9rf79zvd8fflxr-->\n|}");
 add("selser", "1. Table tag in SOL posn. should get reparsed correctly with 
valid TSR [0,[0,[[3],3]]]", "{{echo|}}{| width = '100%'\n|}");
 add("selser", "1. Table tag in SOL posn. should get reparsed correctly with 
valid TSR [0,[0,[2,0]]]", "{{echo|}}{| width = 
'100%'\n<!--gqnq56unxcu9pb9-->|foo\n|}");
@@ -1911,7 +1911,7 @@
 add("selser", "Fuzz testing: Parser21 [[4,[2]]]", 
"{|<!--kky0a6mymhwfusor--><!--we67bat81qlx47vi-->\n! irc://{{ftp://a\"; 
onmouseover=\"alert('hello world');\"\n||}");
 add("selser", "Fuzz testing: Parser21 [[3,[1]]]", "{|\n! irc://{{ftp://a\"; 
onmouseover=\"alert('hello world');\"\n||}");
 add("selser", "Fuzz testing: Parser21 [[0,[[[0,2,0],0,0]]]]", "{|\n! 
6ro52eq6kkzf47vi<nowiki/>irc://{{ftp://a\"; onmouseover=\"alert('hello 
world');\"\n||}");
-add("selser", "Fuzz testing: Parser21 [[2,[[3,0,0]]]]", 
"{|<!--91khydnxj2it3xr-->\n||}");
+add("selser", "Fuzz testing: Parser21 [[2,[[3,0,0]]]]", 
"{|<!--91khydnxj2it3xr-->\n\n||}");
 add("selser", "Fuzz testing: Parser21 [[0,[[[4,[4],0],0,0]]]]", 
"{|\n!1z6izy471osf9a4i[irc://{{ftp://a 35m7cjzb2mrhpvi]\" 
onmouseover=\"alert('hello world');\"\n||}");
 add("selser", "Fuzz testing: Parser21 [2]", "k8ttddjg2wxez5mi\n{|\n! 
irc://{{ftp://a\"; onmouseover=\"alert('hello world');\"\n|");
 add("selser", "Fuzz testing: Parser21 [[2,[2]]]", 
"{|<!--10dd0n612botj4i-->\n<!--9woo9t4yzpmygb9-->! irc://{{ftp://a\"; 
onmouseover=\"alert('hello world');\"\n||}");
@@ -1931,19 +1931,19 @@
 add("selser", "Fuzz testing: Parser22 [[1],4,2]", 
"http://===r:::https://b\n\nptlivvbl2mg3nmi\n\noxiqusjba1wqm2t9\n{|");
 add("selser", "Fuzz testing: Parser22 [3,0,0]", "\n{|");
 add("selser", "Fuzz testing: Parser22 [1,0,2]", 
"http://===r:::https://b\n\n3ql477um4peyu8fr\n{|");
-add("selser", "Fuzz testing: Parser24 [0,0,1]", "{| 
data-foobar=\"g6r38jevgd37hkt9\"\n||}");
+add("selser", "Fuzz testing: Parser24 [0,0,1]", "{| 
data-foobar=\"g6r38jevgd37hkt9\"\n\n||}");
 add("selser", "Fuzz testing: Parser24 [0,4,3]", "\n\naosym28xh3ibpgb9\n");
-add("selser", "Fuzz testing: Parser24 [1,3,1]", "<nowiki>{{{|</nowiki>\n<u 
class=\"|\" {{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" />\n{| 
data-foobar=\"6fgt6dvgb9j7zaor\"\n||}");
+add("selser", "Fuzz testing: Parser24 [1,3,1]", "<nowiki>{{{|</nowiki>\n<u 
class=\"|\" {{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" />\n{| 
data-foobar=\"6fgt6dvgb9j7zaor\"\n\n||}");
 add("selser", "Fuzz testing: Parser24 [[4,0],0,[0,3]]", "11sr1z4igrvpwrk9<u 
class=\"|\" {{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" />{|\n\n|}");
 add("selser", "Fuzz testing: Parser24 [3,2,4]", 
"u39lbr4wb5ptlnmi\n\n\n\nng2zinxre265hfr\n");
 add("selser", "Fuzz testing: Parser24 [0,3,[2,3]]", 
"\n{|<!--aruqvd6sv8bvgqfr-->\n\n|}");
-add("selser", "Fuzz testing: Parser24 [4,4,[2,1]]", 
"u2mgcfdhu9d7k3xr\n\nt2gfu2pam7vi\n{|<!--wl9sr7uggvjf9a4i-->\n||}");
+add("selser", "Fuzz testing: Parser24 [4,4,[2,1]]", 
"u2mgcfdhu9d7k3xr\n\nt2gfu2pam7vi\n{|<!--wl9sr7uggvjf9a4i-->\n\n||}");
 add("selser", "Fuzz testing: Parser24 [[3,0],0,[2,3]]", "<u class=\"|\" 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" 
/>{|<!--gvuyg42a70y3c8fr-->\n\n|}");
-add("selser", "Fuzz testing: Parser24 [2,4,[0,2]]", 
"zp55fn0uhjrio1or\n\n\n\nbywvnpoau9za1yvi\n{|\n<!--zezekrjhlor2uik9-->||}");
-add("selser", "Fuzz testing: Parser24 [0,0,[2,0]]", 
"{|<!--78ok5mnhx8icz0k9-->\n||}");
+add("selser", "Fuzz testing: Parser24 [2,4,[0,2]]", 
"zp55fn0uhjrio1or\n\n\n\nbywvnpoau9za1yvi\n{|\n\n<!--zezekrjhlor2uik9-->||}");
+add("selser", "Fuzz testing: Parser24 [0,0,[2,0]]", 
"{|<!--78ok5mnhx8icz0k9-->\n\n||}");
 add("selser", "Fuzz testing: Parser24 [[2,0],0,[3,[3]]]", 
"<nowiki>9c088ry7flmcxr{{{|</nowiki>\n<u class=\"|\" 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" />{|\n|}");
-add("selser", "Fuzz testing: Parser24 [1,2,[0,[3]]]", 
"<nowiki>{{{|</nowiki>\n<u class=\"|\" 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" 
/>\n\n2ee2y1k6jblkrzfr\n\n{|\n|}");
-add("selser", "Fuzz testing: Parser24 [3,0,1]", "MOVE YOUR MOUSE CURSOR OVER 
THIS TEXT\n{| data-foobar=\"vpeg0ehvafijatt9\"\n||}");
+add("selser", "Fuzz testing: Parser24 [1,2,[0,[3]]]", 
"<nowiki>{{{|</nowiki>\n<u class=\"|\" 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" 
/>\n\n2ee2y1k6jblkrzfr\n\n{|\n\n|}");
+add("selser", "Fuzz testing: Parser24 [3,0,1]", "MOVE YOUR MOUSE CURSOR OVER 
THIS TEXT\n{| data-foobar=\"vpeg0ehvafijatt9\"\n\n||}");
 add("selser", "Fuzz testing: Parser24 [4,4,[3,[2]]]", 
"vtpmggos1rxm9529\n\ntg1e2avwggbymn29\n{|<!--yi16pa7w3cv7vi-->\n||}");
 add("selser", "Fuzz testing: Parser24 [[2,0],1,2]", 
"<nowiki>948zfqhejm8l4n29{{{|</nowiki>\n<u class=\"|\" 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" />\n\nMOVE YOUR MOUSE CURSOR 
OVER THIS TEXT\n\nwvwpzfhipqqfflxr\n{|\n{{{|\n<u CLASS=\n| 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}} >\n<br 
style=\"onmouseover='alert(document.cookie);' \" />\n\nMOVE YOUR MOUSE CURSOR 
OVER THIS TEXT\n|");
 add("selser", "Fuzz testing: Parser24 [[2,0],2,[4,[2]]]", 
"<nowiki>hndosskzwiiwl8fr{{{|</nowiki>\n<u class=\"|\" 
{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}}>\n<br 
style=\"onmouseover='alert(document.cookie);' \" 
/>\n\nsk3rl6utosgojemi\n\n{|<!--jzny1t7i47mygb9--><!--8oeybhmbp7lanhfr-->\n||}");

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I615d6dc3399a0bef5707463ce6188ff36b247185
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <ssas...@wikimedia.org>
Gerrit-Reviewer: Arlolra <abrea...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to