File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed
Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ Many additional bugs fixed.
7575 const appealReason = hrEl . nextElementSibling . nextElementSibling . childNodes [ 0 ] . textContent ;
7676 // FIXME: should handle this case (|reason=\nText, https://github.com/NovemLinguae/UserScripts/issues/240) instead of throwing an error
7777 if ( appealReason === '\n' ) {
78- mw . notify ( 'UnblockReview error 1 : unable to find decline reason by scanning HTML' , { type : 'error' } ) ;
78+ mw . notify ( 'UnblockReview error: unable to find decline reason by scanning HTML' , { type : 'error' } ) ;
7979 return ;
8080 }
8181
@@ -86,15 +86,22 @@ Many additional bugs fixed.
8686 // eslint-disable-next-line no-undef
8787 const unblockReview = new UnblockReview ( ) ;
8888 const acceptDeclineReason = reasonArea . value ;
89- const wikitext2 = unblockReview . processAcceptOrDecline (
90- wikitext ,
91- appealReason ,
92- acceptDeclineReason ,
93- DEFAULT_DECLINE_REASON ,
94- acceptOrDecline
95- ) ;
89+ let wikitext2 ;
90+ try {
91+ wikitext2 = unblockReview . processAcceptOrDecline (
92+ wikitext ,
93+ appealReason ,
94+ acceptDeclineReason ,
95+ DEFAULT_DECLINE_REASON ,
96+ acceptOrDecline
97+ ) ;
98+ } catch ( e ) {
99+ mw . notify ( 'UnblockReview error: ' + e . message , { type : 'error' } ) ;
100+ return ;
101+ }
102+
96103 if ( wikitext === wikitext2 ) {
97- mw . notify ( 'UnblockReview error 2 : unable to determine write location.' , { type : 'error' } ) ;
104+ mw . notify ( 'UnblockReview error: unable to determine write location.' , { type : 'error' } ) ;
98105 return ;
99106 }
100107
Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ export class UnblockReview {
3737 // eslint-disable-next-line no-useless-concat
3838 const negativeLookbehinds = '(?<!<' + 'nowiki>)' ;
3939 const regEx = new RegExp ( negativeLookbehinds + this . escapeRegExp ( initialText + paramsAndReason ) , 'g' ) ;
40+ const count = ( wikitext . match ( regEx ) || [ ] ) . length ;
41+ if ( count > 1 ) {
42+ throw new Error ( 'Too many matching unblock templates found' ) ;
43+ }
44+
4045 const templateName = initialText . match ( / ^ \{ \{ ( [ A - Z a - z - ] + ) / i ) [ 1 ] ;
4146 let wikitext2 = wikitext . replace (
4247 regEx ,
@@ -58,7 +63,7 @@ export class UnblockReview {
5863 }
5964
6065 if ( wikitext === wikitext2 ) {
61- throw new Error ( 'Replacing text with unblock message failed! ' ) ;
66+ throw new Error ( 'Replacing text with unblock message failed' ) ;
6267 }
6368
6469 // get rid of any [#*:] in front of {{unblock X}} templates. indentation messes up the background color and border of the unblock template.
You can’t perform that action at this time.
0 commit comments