From 18204a4b0db597fd9f522728c966cc81b06bbe09 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Fri, 5 Jan 2024 23:53:34 +0530 Subject: [PATCH] Fix parsing logic when comments or hidden characters are present 0c61a5a468ed9b6aafe939f60a60f9257db255e0 subtly affected the gadget definition parsing, causing issues with definitions containing HTML comments or certain kinds of whitespace characters. They would get saved to the pages array with a trailing whitespace but Gadget::getScripts() would only return pages strictly ending in `.js`. Trimming the title before in MediaWikiGadgetsDefinitionRepo fixes the issue. Bug: T354385 Change-Id: Iacee432756006060217981a534434fd455285793 --- includes/MediaWikiGadgetsDefinitionRepo.php | 3 +-- .../integration/MediaWikiGadgetsDefinitionRepoTest.php | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/MediaWikiGadgetsDefinitionRepo.php b/includes/MediaWikiGadgetsDefinitionRepo.php index 33288a1e..2db6fa42 100644 --- a/includes/MediaWikiGadgetsDefinitionRepo.php +++ b/includes/MediaWikiGadgetsDefinitionRepo.php @@ -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 ); diff --git a/tests/phpunit/integration/MediaWikiGadgetsDefinitionRepoTest.php b/tests/phpunit/integration/MediaWikiGadgetsDefinitionRepoTest.php index 0ea5a4de..37559100 100644 --- a/tests/phpunit/integration/MediaWikiGadgetsDefinitionRepoTest.php +++ b/tests/phpunit/integration/MediaWikiGadgetsDefinitionRepoTest.php @@ -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 +* g2 [ResourceLoader | default | namespaces=2 | rights=editmyuserjs] | 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() ); } /**