Skip to content

Commit

Permalink
fix #236 when there's a declined unblock and an open unblock with ide…
Browse files Browse the repository at this point in the history
…ntical reason text, places in wrong location
  • Loading branch information
NovemLinguae committed Nov 7, 2024
1 parent 916ea5e commit e7aa848
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
7 changes: 5 additions & 2 deletions UnblockReview/modules/UnblockReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export class UnblockReview {
acceptDeclineReason = acceptDeclineReason + ' ' + this.SIGNATURE;
}

const negativeLookbehinds = '(?<!<nowiki>)';
const regEx = new RegExp( negativeLookbehinds + this.escapeRegExp( initialText + appealReason ), 'g' );
wikitext = wikitext.replace(
initialText + appealReason,
regEx,
'{{unblock reviewed|' + acceptOrDecline + '=' + acceptDeclineReason + '|1=' + appealReason
);

Expand All @@ -34,7 +36,8 @@ export class UnblockReview {
* This can also handle 1=, and no parameter at all (just a pipe)
*/
getLeftHalfOfUnblockTemplate( wikitext, appealReason ) {
const regEx = new RegExp( this.escapeRegExp( appealReason ), 'g' );
const negativeLookbehinds = '(?<!<nowiki>{{unblock\\|reason=)(?<!reviewed ?\\|1=)';
const regEx = new RegExp( negativeLookbehinds + this.escapeRegExp( appealReason ), 'g' );
let matches = wikitext.matchAll( regEx );
matches = [ ...matches ];
if ( matches.length === 0 ) {
Expand Down
39 changes: 39 additions & 0 deletions UnblockReview/tests/UnblockReview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ describe( 'getLeftHalfOfUnblockTemplate( wikitext, appealReason )', () => {
expect( () => {unblockReview.getLeftHalfOfUnblockTemplate( wikitext, appealReason );} ).toThrow( Error );
expect( () => {unblockReview.getLeftHalfOfUnblockTemplate( wikitext, appealReason );} ).toThrow( "Searching backwards failed!" );
} );

test( 'Skip <nowiki>{{unblock}}', () => {
const wikitext = `Test <code><nowiki>{{unblock|reason=Your reason here ~~~~}}</nowiki></code> Test`;
const appealReason = `Your reason here `;
expect( () => {unblockReview.getLeftHalfOfUnblockTemplate( wikitext, appealReason );} ).toThrow( Error );
expect( () => {unblockReview.getLeftHalfOfUnblockTemplate( wikitext, appealReason );} ).toThrow( "Searching for target text failed!" );
} );
} );

describe( 'processAcceptOrDecline( wikitext, appealReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline )', () => {
Expand Down Expand Up @@ -147,4 +154,36 @@ I would somewhat disagree with you there sir. [[User:Jean Zboncak|Jean Zboncak]]
Seem’st thou thrive if he did banish thee, arm against thy quarrel.`;
expect( unblockReview.processAcceptOrDecline( wikitext, appealReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline ) ).toBe( expected );
} );

test( 'Skip <nowiki>{{unblock}}', () => {
const wikitext =
`<div class="user-block" style="padding: 5px; margin-bottom: 0.5em; border: 1px solid var(--border-color-base, #a2ab91); background-color: var(--background-color-warning-subtle, #fef6e7); color:inherit; min-height: 40px">[[File:Stop x nuvola.svg|40px|left|alt=Stop icon]]<div style="margin-left:45px">You have been '''[[WP:Blocking policy|blocked]]''' '''[[Wikipedia:Blocking_policy#Indefinite_blocks|indefinitely]]''' from editing for [[Wikipedia:Sockpuppetry|abusing multiple accounts]]. Note that multiple accounts are [[Wikipedia:Sockpuppetry#Legitimate uses|allowed]], but '''not for ''[[Wikipedia:Sockpuppetry#Inappropriate uses of alternative accounts|illegitimate]]'' reasons''', and any contributions made while evading blocks or bans may be [[Wikipedia:Banning policy#Edits by and on behalf of banned editors|reverted]] or [[Wikipedia:Criteria for speedy deletion#G5|deleted]]. </div><div style="margin-left:45px">If you think there are good reasons for being unblocked, please review Wikipedia's [[WP:Guide to appealing blocks|guide to appealing blocks]], then add the following text to the bottom of your talk page: <!-- Copy the text as it appears on your page, not as it appears in this edit area. --><code><nowiki>{{unblock|reason=Your reason here ~~~~}}</nowiki></code>. &nbsp;[[User:Ponyo|<span style="color: Navy;">'''Ponyo'''</span>]]<sup>[[User talk:Ponyo|<span style="color: Navy;">''bons mots''</span>]]</sup> 18:18, 25 October 2024 (UTC)</div></div><!-- Template:uw-sockblock -->
{{unblock|reason=Your reason here [[User:Rathoremohanrathore|Rathoremohanrathore]] ([[User talk:Rathoremohanrathore#top|talk]]) 12:12, 30 October 2024 (UTC)}}
`;
const appealReason = `Your reason here `;
const acceptDeclineReason = `Insufficient. ~~~~`;
const acceptOrDecline = `decline`;
const expected =
`<div class="user-block" style="padding: 5px; margin-bottom: 0.5em; border: 1px solid var(--border-color-base, #a2ab91); background-color: var(--background-color-warning-subtle, #fef6e7); color:inherit; min-height: 40px">[[File:Stop x nuvola.svg|40px|left|alt=Stop icon]]<div style="margin-left:45px">You have been '''[[WP:Blocking policy|blocked]]''' '''[[Wikipedia:Blocking_policy#Indefinite_blocks|indefinitely]]''' from editing for [[Wikipedia:Sockpuppetry|abusing multiple accounts]]. Note that multiple accounts are [[Wikipedia:Sockpuppetry#Legitimate uses|allowed]], but '''not for ''[[Wikipedia:Sockpuppetry#Inappropriate uses of alternative accounts|illegitimate]]'' reasons''', and any contributions made while evading blocks or bans may be [[Wikipedia:Banning policy#Edits by and on behalf of banned editors|reverted]] or [[Wikipedia:Criteria for speedy deletion#G5|deleted]]. </div><div style="margin-left:45px">If you think there are good reasons for being unblocked, please review Wikipedia's [[WP:Guide to appealing blocks|guide to appealing blocks]], then add the following text to the bottom of your talk page: <!-- Copy the text as it appears on your page, not as it appears in this edit area. --><code><nowiki>{{unblock|reason=Your reason here ~~~~}}</nowiki></code>. &nbsp;[[User:Ponyo|<span style="color: Navy;">'''Ponyo'''</span>]]<sup>[[User talk:Ponyo|<span style="color: Navy;">''bons mots''</span>]]</sup> 18:18, 25 October 2024 (UTC)</div></div><!-- Template:uw-sockblock -->
{{unblock reviewed|decline=Insufficient. ~~~~|1=Your reason here [[User:Rathoremohanrathore|Rathoremohanrathore]] ([[User talk:Rathoremohanrathore#top|talk]]) 12:12, 30 October 2024 (UTC)}}
`;
expect( unblockReview.processAcceptOrDecline( wikitext, appealReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline ) ).toBe( expected );
} );

test( 'Skip {{unblock reviewed}}', () => {
const wikitext =
`{{unblock reviewed |1=Your reason here [[User:Rathoremohanrathore|Rathoremohanrathore]] ([[User talk:Rathoremohanrathore#top|talk]]) 12:06, 30 October 2024 (UTC) |decline = One open unblock request at a time, please. {{confirmed}} sockpuppetry to {{np|Lalmohanlal}}. You are now considered [[WP:CBAN|banned by the community]] under [[WP:3X]] due to your chronic [[WP:EVADE|block evasion]]. [[User:Yamla|Yamla]] ([[User talk:Yamla|talk]]) 12:10, 30 October 2024 (UTC)}}
{{unblock|reason=Your reason here [[User:Rathoremohanrathore|Rathoremohanrathore]] ([[User talk:Rathoremohanrathore#top|talk]]) 12:12, 30 October 2024 (UTC)}}
`;
const appealReason = `Your reason here `;
const acceptDeclineReason = `Insufficient. ~~~~`;
const acceptOrDecline = `decline`;
const expected =
`{{unblock reviewed |1=Your reason here [[User:Rathoremohanrathore|Rathoremohanrathore]] ([[User talk:Rathoremohanrathore#top|talk]]) 12:06, 30 October 2024 (UTC) |decline = One open unblock request at a time, please. {{confirmed}} sockpuppetry to {{np|Lalmohanlal}}. You are now considered [[WP:CBAN|banned by the community]] under [[WP:3X]] due to your chronic [[WP:EVADE|block evasion]]. [[User:Yamla|Yamla]] ([[User talk:Yamla|talk]]) 12:10, 30 October 2024 (UTC)}}
{{unblock reviewed|decline=Insufficient. ~~~~|1=Your reason here [[User:Rathoremohanrathore|Rathoremohanrathore]] ([[User talk:Rathoremohanrathore#top|talk]]) 12:12, 30 October 2024 (UTC)}}
`;
expect( unblockReview.processAcceptOrDecline( wikitext, appealReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline ) ).toBe( expected );
} );
} );

0 comments on commit e7aa848

Please sign in to comment.