Skip to content

Commit

Permalink
fix processDelistForGAList() over-deletion bug
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Jan 18, 2023
1 parent 1bef0d1 commit 0ac9582
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GANReviewTool/modules/GARCloserWikicodeGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ __TOC__`;

processDelistForGAList(wikicode, articleToRemove) {
if ( arguments.length !== 2 ) throw new Error('Incorrect # of arguments');
let regex = new RegExp(`'{0,3}"?\\[\\[${this.regExEscape(articleToRemove)}.*\\]\\]"?'{0,3}\\n`, 'g');
let regex = new RegExp(`'{0,3}"?\\[\\[${this.regExEscape(articleToRemove)}(?:\\|[^\\]]+)?\\]\\]"?'{0,3}\\n`, 'gi');
wikicode = wikicode.replace(regex, '');
return wikicode;
}
Expand Down
25 changes: 24 additions & 1 deletion GANReviewTool/tests/GARCloserWikicodeGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,6 @@ describe('processDelistForGAList(wikicode, articleToRemove)', () => {
expect(wg.processDelistForGAList(wikicode, articleToRemove)).toBe(output);
});


it(`Should handle rare case of the item being listed twice`, () => {
let articleToRemove = `Multilateral Investment Guarantee Agency`;
let wikicode =
Expand Down Expand Up @@ -1041,6 +1040,30 @@ describe('processDelistForGAList(wikicode, articleToRemove)', () => {
''[[The Accounting Review]]''
[[Mzoli's]]
}}
`;
expect(wg.processDelistForGAList(wikicode, articleToRemove)).toBe(output);
});

it(`Should delete the exact article name only`, () => {
let articleToRemove = `Fish`;
let wikicode =
`===== Globalization =====
{{#invoke:Good Articles|subsection|
[[Globalization and women in China]]
[[Fish allergy]]
[[Fish]]
[[Fisher (animal)]]
[[Spanish flu]]
}}
`;
let output =
`===== Globalization =====
{{#invoke:Good Articles|subsection|
[[Globalization and women in China]]
[[Fish allergy]]
[[Fisher (animal)]]
[[Spanish flu]]
}}
`;
expect(wg.processDelistForGAList(wikicode, articleToRemove)).toBe(output);
});
Expand Down

0 comments on commit 0ac9582

Please sign in to comment.