Skip to content

Commit

Permalink
handle a space at the end of the template name
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Aug 26, 2024
1 parent 680be46 commit 205c403
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/modules/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,9 @@
const uniqueBanners = [];
const bannerMap = {};
banners.forEach( ( banner ) => {
const bannerKey = banner.toLowerCase().match( /{{[^|}]+/ )[ 0 ];
let bannerKey = banner.toLowerCase().match( /{{[^|}]+/ )[ 0 ];
// get rid of whitespace at the end of the template name
bannerKey = bannerKey.trim();
if ( !bannerMap[ bannerKey ] ) {
uniqueBanners.push( banner );
bannerMap[ bannerKey ] = true;
Expand Down
11 changes: 11 additions & 0 deletions tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,15 @@ describe( 'AFCH.removeDuplicateBanners', () => {
'{{WikiProject Ontario}}'
] );
} );

it( 'should handle a space at the end of the template name', () => {
const banners = [
'{{WikiProject Military history |Indian-task-force=yes}}',
'{{WikiProject Military history}}'
];
const output = AFCH.removeDuplicateBanners( banners );
expect( output ).toEqual( [
'{{WikiProject Military history |Indian-task-force=yes}}'
] );
} );
} );

0 comments on commit 205c403

Please sign in to comment.