From 8384d48ae019ce0f3732a83235b86e3696891ee9 Mon Sep 17 00:00:00 2001 From: Arlo Breault Date: Tue, 23 Oct 2018 18:47:48 -0400 Subject: [PATCH] parser: Remove trailing newline after prefixes have been cleared Bug: T208070 Depends-On: I74953d5de765a2245a2999f17c7ae1cf49376bd1 Change-Id: I05511aee275238954f22db78616b19ce10cd6490 --- includes/parser/BlockLevelPass.php | 4 +- tests/parser/parserTests.txt | 78 +---------------------- tests/phpunit/includes/OutputPageTest.php | 10 +-- 3 files changed, 9 insertions(+), 83 deletions(-) diff --git a/includes/parser/BlockLevelPass.php b/includes/parser/BlockLevelPass.php index 288a52704e..b8ff75692a 100644 --- a/includes/parser/BlockLevelPass.php +++ b/includes/parser/BlockLevelPass.php @@ -403,7 +403,9 @@ class BlockLevelPass { while ( $prefixLength ) { $output .= $this->closeList( $prefix2[$prefixLength - 1] ); --$prefixLength; - if ( !$prefixLength ) { + // Note that `lastSection` is only ever set when `prefixLength` + // is zero, but we'll choose to be overly cautious. + if ( !$prefixLength && $this->lastSection !== '' ) { $output .= "\n"; } } diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 7ef057a925..d64089b447 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -668,7 +668,6 @@ Simple list !! html - !! end !! test @@ -705,7 +704,6 @@ Italics and bold
  • plainboldbold-italicplain
  • plain l'italicplain
  • plain l'bold plain
  • - !! end # this example taken from the [[simple:Moon]] article (T49326) @@ -1575,7 +1573,6 @@ nowiki 3
  • There is nowiki.
  • - !! html/parsoid
    There is not nowiki.
    There is nowiki.
    @@ -1980,7 +1977,6 @@ parsoid=wt2html,wt2wt !! html/php - !! html/parsoid - !! end @@ -4616,7 +4589,6 @@ Definition Lists: Mixed Lists: Test 5 !! html - !! end @@ -4628,7 +4600,6 @@ Definition Lists: Mixed Lists: Test 6 !! html
      • d1
        d3
    - !! end @@ -4640,7 +4611,6 @@ Definition Lists: Mixed Lists: Test 7 !! html
    • d1
    • d2
    - !! end @@ -4652,7 +4622,6 @@ Definition Lists: Mixed Lists: Test 8 !! html
    • d1
    • d2
    - !! end @@ -4663,7 +4632,6 @@ Definition Lists: Mixed Lists: Test 9 !! html - !! end @@ -4674,7 +4642,6 @@ Definition Lists: Mixed Lists: Test 10 !! html - !! end # The Parsoid team disagrees with the PHP parser's seemingly-random @@ -4692,7 +4659,6 @@ Definition Lists: Mixed Lists: Test 11
    a
    • b
    - !! html/parsoid
    a
    • b
    @@ -4709,7 +4675,6 @@ Definition Lists: Mixed Lists: Test 12
    boo
    baz
    - !! html/php+tidy - !! html/parsoid

    http://[2404:130:0:1000::187:2]/index.php

    @@ -6025,7 +5989,6 @@ Examples from RFC 2732, section 2:
  • 5
  • 6
  • 7
  • - !! html/parsoid

    test

    @@ -8866,7 +8829,6 @@ parsoid=wt2html,wt2wt !! html/php - !! html/php+tidy @@ -9873,7 +9835,6 @@ Common list - !! end !! test @@ -9886,7 +9847,6 @@ Numbered list
    1. Numbered list
    2. item 2
    3. item 3
    - !! end # the switch from level 3 to ordered should not introduce a newline between @@ -9924,7 +9884,6 @@ Mixed list
  • Level 1
        • Level 3, but ordered
    - !! end !! test @@ -9939,7 +9898,6 @@ Mixed list
  • hi
  • - !! html/parsoid - !! end # XXX this test should be moved to citeParserTests, since it depends @@ -10073,7 +10022,6 @@ Nested lists 9 (extension interaction) - !! end !! test @@ -10094,7 +10042,6 @@ Nested lists 10 (list and span siblings: wt2wt regression) !! html - !! end !! test @@ -10107,7 +10054,6 @@ List items are not parsed correctly following a
     block (T2785)
     
    -
     !! html/parsoid
     
    -
     !! end
     
     !! test
    @@ -10155,7 +10100,6 @@ List interrupted by empty line or heading
     
     

    A heading[edit]

    - !!end !! test @@ -10235,7 +10179,6 @@ Single-comment whitespace lines dont break lists, and neither do multi-comment w
  • b
  • c
  • d
  • - !!end !!test @@ -10254,7 +10197,6 @@ Replacing whitespace with tabs still doesn't break the list (gerrit 78327)
  • b
  • c
  • d
  • - !!end # FIXME: Parsoid has a dedicated DOM pass to mimic this Tidy-specific li-hack @@ -10620,7 +10562,6 @@ Magic Words LOCAL (UTC)
  • 1
  • 4
  • 19700101000203
  • - !! end !! test @@ -11694,7 +11635,6 @@ Templates with templated name

    foo

    - !! html/parsoid

    foo

    @@ -12558,7 +12498,6 @@ Preprocessor precedence 5: tplarg takes precedence over template {{Precedence5|Bullet}} !! html/php - !! html/parsoid !! end @@ -12658,7 +12597,6 @@ Preprocessor precedence 9: groups of braces
    Four
    7
    {Bullet}
    - !! html/parsoid
    4
    @@ -12710,7 +12648,6 @@ language=zh
    -Three-
    7
    raw2
    - !! html/parsoid
    1
    @@ -13763,7 +13700,6 @@ unused}}}} !! html - !!end !!test @@ -21201,7 +21137,6 @@ Handling of in URLs *irc:// a !! html/php - !! html/parsoid !! end @@ -21212,7 +21147,6 @@ Handling of %0A in URLs *irc://%0Aa !! html/php - !! html/parsoid !! end @@ -21329,7 +21263,6 @@ title=[[Parser test]]
  • Template:Dynamic
  • - !! end ### Note: Above tests excludes the "{{NUMBEROFADMINS}}" magic word because it generates a MySQL error when included. @@ -22320,7 +22253,6 @@ dt/dd/dl test :;;;:: !! html/php
    - !! html/parsoid
    @@ -22479,7 +22411,6 @@ Definition list code coverage
    def
    title
    def
    - !! html/parsoid
    title
    def
    title
    def
    @@ -23885,7 +23816,6 @@ language=zh variant=zh-cn !! html/php
    AAA
    foo:bar
    - !! html/parsoid
    @@ -23903,8 +23833,7 @@ language=zh variant=zh-cn ;-{zh-cn:AAA !! html/php+tidy
    foo:bar
    -
    -{zh-cn:AAA

    -

    +
    -{zh-cn:AAA
    !! html/parsoid
    foo:bar
    -{zh-cn
    AAA
    @@ -23919,7 +23848,6 @@ language=zh variant=zh-cn !! html/php
    AAA foo:bar bat:baz
    def
    - !! html/parsoid
    def
    @@ -24076,7 +24004,6 @@ T2529: Uncovered bullet !! html
    • Foo
    • Bar
    - !! end !! test @@ -24086,7 +24013,6 @@ T2529: Uncovered bullet in a deeply nested list !! html
                • Foo
    • Bar
    - !! end !! test @@ -24119,7 +24045,6 @@ T2529: Uncovered bullet in parser function result !! html
    • Foo
    • bar
    - !! end !! test @@ -24949,7 +24874,6 @@ paragraphs 04=Foobar.jpg 05=
    • foo
    • bar
    - 06=foo 07=
    Preformatted
     
    diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index aa14124a2c..92765cb0d0 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -1534,7 +1534,7 @@ class OutputPageTest extends MediaWikiTestCase { '

    ' . "\nMy message\n

    " ], 'List at start' => [ [ '* List' ], - "
    • List
    \n", + "
    • List
    ", ], 'List not at start' => [ [ '* Not a list', false ], '

    * Not a list

    ', @@ -1829,12 +1829,12 @@ class OutputPageTest extends MediaWikiTestCase { return [ 'List at start of line (content)' => [ [ '* List', true, false ], - "
    • List
    \n
    ", - "
    • List
    \n", + "
    • List
    ", + "
    • List
    ", ], 'List at start of line (interface)' => [ [ '* List', true, true ], - "
    • List
    \n", + "
    • List
    ", ], 'List not at start (content)' => [ [ "* ''Not'' list", false, false ], @@ -1925,7 +1925,7 @@ class OutputPageTest extends MediaWikiTestCase { return [ 'List at start of line' => [ [ '* List', true ], - "
    • List
    \n", + "
    • List
    ", ], 'List not at start' => [ [ "* ''Not'' list", false ], -- 2.20.1