Merge "Fix parsing logic when comments or hidden characters are present"

This commit is contained in:
jenkins-bot 2024-01-06 16:22:33 +00:00 committed by Gerrit Code Review
commit 95e524ffe7
2 changed files with 7 additions and 3 deletions

View file

@ -303,8 +303,7 @@ class MediaWikiGadgetsDefinitionRepo extends GadgetRepo {
}
foreach ( preg_split( '/\s*\|\s*/', $pages, -1, PREG_SPLIT_NO_EMPTY ) as $page ) {
$page = $this->titlePrefix . $page;
$info['pages'][] = $page;
$info['pages'][] = $this->titlePrefix . trim( $page );
}
return new Gadget( $info );

View file

@ -18,6 +18,8 @@ class MediaWikiGadgetsDefinitionRepoTest extends MediaWikiIntegrationTestCase {
* baz [rights=read] |baz.js
==keep-section2==
* quux [rights=read] | quux.js
* g1 [ResourceLoader | default | namespaces=2 | rights=editmyuserjs] | g1.js <!-- comment -->
* g2 [ResourceLoader | default | namespaces=2 | rights=editmyuserjs] | <!-- comment --> g2.js
EOT;
$this->editPage( 'MediaWiki:Gadgets-definition', $gadgetsDef );
@ -25,10 +27,13 @@ EOT;
$repo = new MediaWikiGadgetsDefinitionRepo( $services->getMainWANObjectCache(),
$services->getRevisionLookup() );
$gadgets = $repo->fetchStructuredList();
$this->assertCount( 4, $gadgets );
$this->assertCount( 6, $gadgets );
$bar = $repo->getGadget( 'bar' );
$this->assertEquals( 'keep-section1', $bar->toArray()['category'] );
$this->assertEquals( [ 'MediaWiki:Gadget-g1.js' ], $repo->getGadget( 'g1' )->getScripts() );
$this->assertEquals( [ 'MediaWiki:Gadget-g2.js' ], $repo->getGadget( 'g2' )->getScripts() );
}
/**