From 205c4039e119301b55cfaa33cdbb9e7280ea3389 Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Mon, 26 Aug 2024 05:00:22 -0700 Subject: [PATCH] handle a space at the end of the template name --- src/modules/core.js | 4 +++- tests/test-core.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/modules/core.js b/src/modules/core.js index 8a667e42..5d2e9240 100644 --- a/src/modules/core.js +++ b/src/modules/core.js @@ -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; diff --git a/tests/test-core.js b/tests/test-core.js index 14447323..0bc9a187 100644 --- a/tests/test-core.js +++ b/tests/test-core.js @@ -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}}' + ] ); + } ); } );