Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/80168


Change subject: The autoInsertedEnd flags need to go on the open tag (not the 
close tag).
......................................................................

The autoInsertedEnd flags need to go on the open tag (not the close tag).

Change-Id: I661d45dfc1e01f203ed152268cc6e24ac36d6aaf
---
M js/lib/ext.core.QuoteTransformer.js
M js/tests/parserTests-blacklist.js
M js/tests/parserTests.txt
3 files changed, 59 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/68/80168/1

diff --git a/js/lib/ext.core.QuoteTransformer.js 
b/js/lib/ext.core.QuoteTransformer.js
index 613bc04..7f2213b 100644
--- a/js/lib/ext.core.QuoteTransformer.js
+++ b/js/lib/ext.core.QuoteTransformer.js
@@ -171,6 +171,7 @@
 
        // this is the same state machine as the php parser uses.
        var lastboth = -1, state = '';
+       var lastb = null, lasti = null;
        for (i = 1; i < this.chunks.length; i += 2) {
                console.assert(this.chunks[i].length === 1);
                qlen = this.chunks[i][0].value.length;
@@ -178,59 +179,76 @@
                        if (state === 'i') {
                                this.quoteToTag(i, [new EndTagTk( 'i' )]);
                                state = '';
+                               lasti = null;
                        } else if (state === 'bi') {
                                this.quoteToTag(i, [new EndTagTk( 'i' )]);
                                state = 'b';
+                               lasti = null;
                        } else if (state === 'ib') {
                                // annoying!
+                               lastb.dataAttribs.autoInsertedEnd = 1;
                                this.quoteToTag(i, [new EndTagTk( 'b' ), new 
EndTagTk( 'i' ),
-                                                                       new 
TagTk( 'b' )], "bogus two");
+                                                                       lastb = 
new TagTk( 'b' )], "bogus two");
                                state = 'b';
+                               lasti = null;
                        } else if (state === 'both') {
-                               this.quoteToTag(lastboth, [new TagTk( 'b' ), 
new TagTk( 'i' )]);
+                               this.quoteToTag(lastboth, [lastb = new TagTk( 
'b' ),
+                                                                               
   new TagTk( 'i' )]);
                                this.quoteToTag(i, [new EndTagTk( 'i' )]);
                                state = 'b';
+                               lasti = null;
                        } else { // state can be 'b' or ''
-                               this.quoteToTag(i, [new TagTk( 'i' )]);
+                               this.quoteToTag(i, [lasti = new TagTk( 'i' )]);
                                state += 'i';
                        }
                } else if (qlen === 3) {
                        if (state === 'b') {
                                this.quoteToTag(i, [new EndTagTk( 'b' )]);
                                state = '';
+                               lastb = null;
                        } else if (state === 'ib') {
                                this.quoteToTag(i, [new EndTagTk( 'b' )]);
                                state = 'i';
+                               lastb = null;
                        } else if (state === 'bi') {
                                // annoying!
+                               lasti.dataAttribs.autoInsertedEnd = 1;
                                this.quoteToTag(i, [new EndTagTk( 'i' ), new 
EndTagTk( 'b' ),
-                                                                       new 
TagTk( 'i' )], "bogus two");
+                                                                       lasti = 
new TagTk( 'i' )], "bogus two");
                                state = 'i';
+                               lastb = null;
                        } else if (state === 'both') {
-                               this.quoteToTag(lastboth, [new TagTk( 'i' ), 
new TagTk( 'b' )]);
+                               this.quoteToTag(lastboth, [lasti = new TagTk( 
'i' ),
+                                                                               
   new TagTk( 'b' )]);
                                this.quoteToTag(i, [new EndTagTk( 'b' )]);
                                state = 'i';
+                               lastb = null;
                        } else { // state can be 'i' or ''
-                               this.quoteToTag(i, [new TagTk( 'b' )]);
+                               this.quoteToTag(i, [lastb = new TagTk( 'b' )]);
                                state += 'b';
                        }
                } else if (qlen === 5) {
                        if (state === 'b') {
-                               this.quoteToTag(i, [new EndTagTk( 'b' ), new 
TagTk( 'i' )]);
+                               this.quoteToTag(i, [new EndTagTk( 'b' ), lasti 
= new TagTk( 'i' )]);
                                state = 'i';
+                               lastb = null;
                        } else if (state === 'i') {
-                               this.quoteToTag(i, [new EndTagTk( 'i' ), new 
TagTk( 'b' )]);
+                               this.quoteToTag(i, [new EndTagTk( 'i' ), lastb 
= new TagTk( 'b' )]);
                                state = 'b';
+                               lasti = null;
                        } else if (state === 'bi') {
                                this.quoteToTag(i, [new EndTagTk( 'i' ), new 
EndTagTk( 'b' )]);
                                state = '';
+                               lastb = lasti = null;
                        } else if (state === 'ib') {
                                this.quoteToTag(i, [new EndTagTk( 'b' ), new 
EndTagTk( 'i' )]);
                                state = '';
+                               lastb = lasti = null;
                        } else if (state === 'both') {
                                this.quoteToTag(lastboth, [new TagTk( 'i' ), 
new TagTk( 'b' )]);
                                this.quoteToTag(i, [new EndTagTk( 'b' ), new 
EndTagTk( 'i' )]);
                                state = '';
+                               lastb = lasti = null;
                        } else { // state == ''
                                lastboth = i;
                                state = 'both';
@@ -239,17 +257,21 @@
        }
        // now close all remaining tags.  notice that order is important.
        if ( state === 'both' ) {
-               this.quoteToTag(lastboth, [new TagTk( 'b' ), new TagTk( 'i' )]);
+               this.quoteToTag(lastboth, [lastb = new TagTk( 'b' ),
+                                                                  lasti = new 
TagTk( 'i' )]);
                state = 'bi';
        }
        if ( state === 'b' || state === 'ib' ) {
-               this.currentChunk.push( new EndTagTk( 'b', [], 
{autoInsertedEnd:1} ) );
+               this.currentChunk.push( new EndTagTk( 'b' ) );
+               lastb.dataAttribs.autoInsertedEnd = 1;
        }
        if ( state === 'i' || state === 'bi' || state === 'ib' ) {
-               this.currentChunk.push( new EndTagTk( 'i', [], 
{autoInsertedEnd:1} ) );
+               this.currentChunk.push( new EndTagTk( 'i' ) );
+               lasti.dataAttribs.autoInsertedEnd = 1;
        }
        if ( state === 'bi' ) {
-               this.currentChunk.push( new EndTagTk( 'b', [], 
{autoInsertedEnd:1} ) );
+               this.currentChunk.push( new EndTagTk( 'b' ) );
+               lastb.dataAttribs.autoInsertedEnd = 1;
        }
 
        // return all collected tokens including the newline
@@ -300,14 +322,18 @@
        var startpos = tsr ? tsr[0] : null, endpos = tsr ? tsr[1] : null;
        for (var i=0; i<tags.length; i++) {
                if (tsr) {
-                       if ( ( i===0 || i===2) && ignoreBogusTwo ) {
-                               tags[i].dataAttribs.tsr = [ startpos, startpos 
];
+                       if ( i===0 && ignoreBogusTwo ) {
+                               // autoInsertedEnd set by caller
+                               /* jshint noempty: false */
+                       } else if ( i === 2 && ignoreBogusTwo ) {
+                               tags[i].dataAttribs.autoInsertedStart = 1;
                        } else if (tags[i].name === 'b') {
                                tags[i].dataAttribs.tsr = [ startpos, startpos 
+ 3 ];
+                               startpos = tags[i].dataAttribs.tsr[1];
                        } else if (tags[i].name === 'i') {
                                tags[i].dataAttribs.tsr = [ startpos, startpos 
+ 2 ];
+                               startpos = tags[i].dataAttribs.tsr[1];
                        } else { console.assert(false); }
-                       startpos = tags[i].dataAttribs.tsr[1];
                }
                result.push(tags[i]);
        }
diff --git a/js/tests/parserTests-blacklist.js 
b/js/tests/parserTests-blacklist.js
index ec1090e..7514c3a 100644
--- a/js/tests/parserTests-blacklist.js
+++ b/js/tests/parserTests-blacklist.js
@@ -380,7 +380,6 @@
 add("wt2html", "Section extraction, <pre> around bogus header (bug 10309)");
 add("wt2html", "Section replacement, <pre> around bogus header (bug 10309)");
 add("wt2html", "Handling of &#x0A; in URLs");
-add("wt2html", "5 quotes, code coverage +1 line (parsoid)");
 add("wt2html", "Special:Search page linking.");
 add("wt2html", "Say the magic word");
 add("wt2html", "Gallery");
@@ -544,7 +543,7 @@
 add("wt2wt", "Italics and bold: 5-quote opening sequence: (5,2)");
 add("wt2wt", "Italics and bold: 5-quote opening sequence: (5,3)");
 add("wt2wt", "Italics and bold: 5-quote opening sequence: (5,4)");
-add("wt2wt", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid)");
+add("wt2wt", "Italics and bold: multiple quote sequences: (2,4,2)");
 add("wt2wt", "Italics and bold: multiple quote sequences: (2,4,3)");
 add("wt2wt", "Italics and bold: multiple quote sequences: (2,4,4)");
 add("wt2wt", "Italics and bold: multiple quote sequences: (3,4,2) (parsoid)");
@@ -724,7 +723,6 @@
 add("html2html", "Italics and bold: 3-quote opening sequence: (3,5) 
(parsoid)");
 add("html2html", "Italics and bold: 4-quote opening sequence: (4,5) 
(parsoid)");
 add("html2html", "Italics and bold: 5-quote opening sequence: (5,2)");
-add("html2html", "Italics and bold: multiple quote sequences: (2,4,2) 
(parsoid)");
 add("html2html", "Italics and bold: multiple quote sequences: (3,4,2) 
(parsoid)");
 add("html2html", "Italics and bold: multiple quote sequences: (3,4,3) 
(parsoid)");
 add("html2html", "Italics and bold: other quote tests: (3,2,3,2)");
@@ -1231,7 +1229,7 @@
 add("html2wt", "Italics and bold: 5-quote opening sequence: (5,2)");
 add("html2wt", "Italics and bold: 5-quote opening sequence: (5,3)");
 add("html2wt", "Italics and bold: 5-quote opening sequence: (5,4)");
-add("html2wt", "Italics and bold: multiple quote sequences: (2,4,2) 
(parsoid)");
+add("html2wt", "Italics and bold: multiple quote sequences: (2,4,2)");
 add("html2wt", "Italics and bold: multiple quote sequences: (2,4,3)");
 add("html2wt", "Italics and bold: multiple quote sequences: (2,4,4)");
 add("html2wt", "Italics and bold: multiple quote sequences: (3,4,2) 
(parsoid)");
@@ -2309,18 +2307,18 @@
 add("selser", "Italics and bold: 5-quote opening sequence: (5,4) [[1]]");
 add("selser", "Italics and bold: 5-quote opening sequence: (5,4) [[[2]]]");
 add("selser", "Italics and bold: 5-quote opening sequence: (5,4) [[[[4]]]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[1]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[[0,[3]],1]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[2,3]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[1,2]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[2]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[2,1]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[[0,[2]],2]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[[0,[2]],0]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[[2,0],4]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[0,1]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[1,1]]");
-add("selser", "Italics and bold: multiple quote sequences: (2,4,2) (parsoid) 
[[[0,[3]],0]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) [[2]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) [[1]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) [[[2,0]]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) [[[2,2]]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) 
[[[0,[3]]]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) [1]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) [2]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) 
[[[2,[4]]]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) [[[3,2]]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) 
[[[0,[2]]]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) 
[[[3,[2]]]]");
+add("selser", "Italics and bold: multiple quote sequences: (2,4,2) [[[0,2]]]");
 add("selser", "Italics and bold: multiple quote sequences: (2,4,3) [1]");
 add("selser", "Italics and bold: multiple quote sequences: (2,4,3) [[[3,0]]]");
 add("selser", "Italics and bold: multiple quote sequences: (2,4,3) [[2]]");
@@ -3469,7 +3467,9 @@
 add("selser", "Handling of &#x0A; in URLs [[[1]]]");
 add("selser", "Handling of &#x0A; in URLs [[1]]");
 add("selser", "5 quotes, code coverage +1 line (parsoid) [2]");
+add("selser", "5 quotes, code coverage +1 line (parsoid) [[1]]");
 add("selser", "5 quotes, code coverage +1 line (parsoid) [1]");
+add("selser", "5 quotes, code coverage +1 line (parsoid) [[[2]]]");
 add("selser", "5 quotes, code coverage +1 line (parsoid) [[2]]");
 add("selser", "Say the magic word 
[[0,0,4,0,[4,0],0,0,0,3,4,1,0,[3],3,0,3,[3],4,1,4,0,0,[4],0,4,4,0,0,1,0,[3,0],2,[4,0],0,[3,0],0,3,0,4,3,1,0,1]]");
 add("selser", "Say the magic word 
[[0,0,[3,0],3,[3,0],0,[2,0],0,[4],4,3,3,0,0,[3],0,0,4,[3],2,2,4,3,2,0,3,0,0,[4,0],3,[3,0],3,1,4,4,3,2,2,[4,0],2,[2],3,0]]");
diff --git a/js/tests/parserTests.txt b/js/tests/parserTests.txt
index fd1102e..0958217 100644
--- a/js/tests/parserTests.txt
+++ b/js/tests/parserTests.txt
@@ -696,24 +696,11 @@
 ### multiple quote sequences in a line
 ###
 !! test
-Italics and bold: multiple quote sequences: (2,4,2) (php)
-!! options
-php
+Italics and bold: multiple quote sequences: (2,4,2)
 !! input
 ''foo''''bar''
 !! result
 <p><i>foo'<b>bar</b></i>
-</p>
-!!end
-# The PHP parser strips the empty tags out for giggles; parsoid doesn't.
-!! test
-Italics and bold: multiple quote sequences: (2,4,2) (parsoid)
-!! options
-parsoid
-!! input
-''foo''''bar''
-!! result
-<p><i>foo'<b>bar</b></i><b></b>
 </p>
 !!end
 
@@ -12802,7 +12789,7 @@
 !! input
 '''''
 !! result
-<p><i><b></b></i></p>
+<p><b><i></i></b></p>
 !! end
 
 !! test

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I661d45dfc1e01f203ed152268cc6e24ac36d6aaf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to