Skip to content

Commit

Permalink
fix #235 fails silently sometimes when there are line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
NovemLinguae committed Nov 7, 2024
1 parent 2b30dbd commit 916ea5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions UnblockReview/modules/UnblockReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export class UnblockReview {
}

processAcceptOrDecline( wikitext, appealReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline ) {
// HTML does one line break and wikitext does 2ish. Cut off all text after the first line break to avoid breaking our search algorithm.
appealReason = appealReason.split( '\n' )[ 0 ];

const initialText = this.getLeftHalfOfUnblockTemplate( wikitext, appealReason );

if ( !acceptDeclineReason.trim() ) {
Expand Down
22 changes: 22 additions & 0 deletions UnblockReview/tests/UnblockReview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,26 @@ describe( 'processAcceptOrDecline( wikitext, appealReason, acceptDeclineReason,
const expected = `{{unblock reviewed|decline=Insufficient. ~~~~|1=Your reason here [[User:Filipe46|Filipe46]] ([[User talk:Filipe46#top|talk]]) 21:54, 25 November 2021 (UTC)}}`;
expect( unblockReview.processAcceptOrDecline( wikitext, appealReason, acceptDeclineReason, DEFAULT_DECLINE_REASON, acceptOrDecline ) ).toBe( expected );
} );

test( 'appealReason contains a line break', () => {
const wikitext =
`==Unblock request==
{{unblock|"Clearly not here to build an encyclopedia"
I would somewhat disagree with you there sir. [[User:Jean Zboncak|Jean Zboncak]] ([[User talk:Jean Zboncak#top|talk]]) 22:54, 30 October 2024 (UTC)}}
Seem’st thou thrive if he did banish thee, arm against thy quarrel.`;
const appealReason =
`"Clearly not here to build an encyclopedia"
I would somewhat disagree with you there sir. `;
const acceptDeclineReason = `Insufficient. ~~~~`;
const acceptOrDecline = `decline`;
const expected =
`==Unblock request==
{{unblock reviewed|decline=Insufficient. ~~~~|1="Clearly not here to build an encyclopedia"
I would somewhat disagree with you there sir. [[User:Jean Zboncak|Jean Zboncak]] ([[User talk:Jean Zboncak#top|talk]]) 22:54, 30 October 2024 (UTC)}}
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 );
} );
} );

0 comments on commit 916ea5e

Please sign in to comment.