From 51e7f733c6b426021327b6e95adf0f0c56c9727b Mon Sep 17 00:00:00 2001 From: NovemLinguae Date: Sat, 3 Jun 2023 08:01:46 -0700 Subject: [PATCH] handle disabled categories --- src/modules/core.js | 2 +- tests/test-core.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/core.js b/src/modules/core.js index 751e4863..c107a3da 100644 --- a/src/modules/core.js +++ b/src/modules/core.js @@ -1585,7 +1585,7 @@ * @param {string} wikicode */ removeEmptySectionAtEnd: function ( wikicode ) { - result = wikicode.replace( /(\n)==[^=]+==\n\s*?(\[\[Category:|$)/i, '$1$2' ); + result = wikicode.replace( /(\n)==[^=]+==\n\s*?(\[\[:?Category:|$)/i, '$1$2' ); var headingWasRemoved = result !== wikicode; if ( headingWasRemoved ) { result = result.replace( /\n\n$/, '\n' ); diff --git a/tests/test-core.js b/tests/test-core.js index dbc9abb6..b43eca4b 100644 --- a/tests/test-core.js +++ b/tests/test-core.js @@ -62,6 +62,12 @@ describe( 'AFCH.removeEmptySectionAtEnd', function () { expect( output ).toBe( 'Test\n\n==Test2==\n\n[[Category:Test]]\n' ); } ); + it( 'disabled category', function () { + var wikicode = 'Test\n\n==Test2==\n\n== Test 3 ==\n\n[[:Category:Test]]\n'; + var output = AFCH.removeEmptySectionAtEnd( wikicode ); + expect( output ).toBe( 'Test\n\n==Test2==\n\n[[:Category:Test]]\n' ); + } ); + it( 'two headings without body text and with two categories #1', function () { var wikicode = 'Test\n\n==Test2==\n\n== Test 3 ==\n\n[[Category:Test]]\n[[Category:Test2]]\n'; var output = AFCH.removeEmptySectionAtEnd( wikicode );