diff options
author | Subramanya Sastry <ssastry@wikimedia.org> | 2025-03-01 18:43:26 -0600 |
---|---|---|
committer | C. Scott Ananian <cscott@cscott.net> | 2025-03-13 12:50:16 -0400 |
commit | 65e671bb809773bba40257288e890d8f24d824fd (patch) | |
tree | 98d7ad1993dc57beb90004a5ecb3c3c33f7ee11a /tests/phpunit/includes/parser | |
parent | 4bf673cc62cc9752e6dea6a91671f367dfd496ed (diff) | |
download | mediawikicore-65e671bb809773bba40257288e890d8f24d824fd.tar.gz mediawikicore-65e671bb809773bba40257288e890d8f24d824fd.zip |
Fixes to "Parsoid Fragment Support v2"
* In 387061415a38ea2d28e76ac9d7d599f6f02deec3, we added support for
StripState::split. In 8465c722, we added support for 'exttag' strip
marker which introduced the possibility of recursive strip
markers. This patch fixes the oversight and adds recursive
processing for nested strip markers. The code matches the logic of
unstripType. Verified on local wiki that this fixes the issues
highlighted in T387608.
* Ensure that processNowiki is true when fragment mode v2 is being
used (ie, when stripExtTags is false). This makes unnecessary the
StripState::replaceNoWikis() function added to support
mw.text.unstripNoWiki in T272507 (and broken in T387655). The
workaround can be cleaned up once v2 fragment mode is enabled
everywhere. This fixes a regression in Scribunto's
mw.text.unstripNoWiki function when v2 fragment mode is used.
* Ensure that the T299103 workaround for {{#tag:<nowiki>...</nowiki>}}
continues to work by calling unstripNowiki() after PROCESS_NOWIKI
puts the <nowiki> contents into the strip state. This fixes a regression
in {{#tag:syntaxhighlight|<nowiki>....</nowiki>}} when using v2
fragment mode.
* Added 'marker' to StripState::split() output, so that unhandled
strip state components can be left as strip markers.
* Added some StripState::split() phpunit tests.
* Changed ParserTestRunner to enable v2 fragment mode by default,
which helped identify the Scribunto and SyntaxHighlight regressions
above, covered by their parser test suites.
Bug: T387608
Bug: T387655
Bug: T272507
Co-Authored-By: C. Scott Ananian <cananian@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Depends-On: I5e2533b7992b8e8a03fe2ea622b6fe5b008d20be
Change-Id: I43134281e4da1c8767520e418031935447ea93af
Diffstat (limited to 'tests/phpunit/includes/parser')
-rw-r--r-- | tests/phpunit/includes/parser/StripStateTest.php | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/tests/phpunit/includes/parser/StripStateTest.php b/tests/phpunit/includes/parser/StripStateTest.php index 9114ae706e41..e97c55adcac6 100644 --- a/tests/phpunit/includes/parser/StripStateTest.php +++ b/tests/phpunit/includes/parser/StripStateTest.php @@ -10,14 +10,17 @@ use MediaWikiIntegrationTestCase; * @covers \MediaWiki\Parser\StripState */ class StripStateTest extends MediaWikiIntegrationTestCase { + private int $markerValue = 0; + protected function setUp(): void { parent::setUp(); $this->setContentLang( 'qqx' ); + $this->markerValue = 0; } private function getMarker() { - static $i; - return Parser::MARKER_PREFIX . '-blah-' . sprintf( '%08X', $i++ ) . Parser::MARKER_SUFFIX; + $i = $this->markerValue++; + return Parser::MARKER_PREFIX . '-blah-' . sprintf( '%08X', $i ) . Parser::MARKER_SUFFIX; } private static function getWarning( $message, $max = '' ) { @@ -179,4 +182,57 @@ class StripStateTest extends MediaWikiIntegrationTestCase { } ); $this->assertSame( $out2, $text ); } + + public function testSplitSimple() { + $ss = new StripState(); + + $nowiki = "<nowiki>''foo''</nowiki>"; + $m1 = $this->getMarker(); + $ss->addNoWiki( $m1, $nowiki ); + + $text = "abc $m1 def"; + $r1 = $ss->split( $text ); + + $expected = [ + [ 'type' => 'string', 'content' => 'abc ' ], + [ 'type' => 'nowiki', 'content' => $nowiki, 'marker' => $m1, ], + [ 'type' => 'string', 'content' => ' def' ], + ]; + $this->assertSame( $expected, $r1 ); + + $ref = "<ref>foo</ref>"; + $m2 = $this->getMarker(); + $ss->addExtTag( $m2, $ref ); + + $text .= $m2; + $r2 = $ss->split( $text ); + $expected = array_merge( $expected, [ + [ 'type' => 'string', 'content' => $ref ], + [ 'type' => 'string', 'content' => '' ] + ] ); + $this->assertSame( $expected, $r2 ); + } + + public function testSplitRecursive() { + $ss = new StripState(); + + $ref = "<ref>foo</ref>"; + $m1 = $this->getMarker(); + $ss->addExtTag( $m1, $ref ); + + $poem = "<poem>foo $m1</poem>"; + $m2 = $this->getMarker(); + $ss->addExtTag( $m2, $poem ); + + $text = "abc $m2"; + $expected = [ + [ 'type' => 'string', 'content' => 'abc ' ], + [ 'type' => 'string', 'content' => '<poem>foo ' ], + [ 'type' => 'string', 'content' => $ref ], + [ 'type' => 'string', 'content' => '</poem>' ], + [ 'type' => 'string', 'content' => '' ], + ]; + $result = $ss->split( $text ); + $this->assertSame( $expected, $result ); + } } |