@@ -200,7 +200,9 @@ export class RedirectsMiddleware extends MiddlewareBase {
200
200
? modifyRedirects . find ( ( redirect : RedirectInfo & { matchedQueryString ?: string } ) => {
201
201
// Modify the redirect pattern to ignore the language prefix in the path
202
202
// And escapes non-special "?" characters in a string or regex.
203
- redirect . pattern = this . escapeNonSpecialQuestionMarks ( redirect . pattern . replace ( RegExp ( `^[^]?/${ language } /` , 'gi' ) , '' ) ) ;
203
+ redirect . pattern = this . escapeNonSpecialQuestionMarks (
204
+ redirect . pattern . replace ( RegExp ( `^[^]?/${ language } /` , 'gi' ) , '' )
205
+ ) ;
204
206
205
207
// Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
206
208
redirect . pattern = `/^\/${ redirect . pattern
@@ -365,9 +367,9 @@ export class RedirectsMiddleware extends MiddlewareBase {
365
367
366
368
/**
367
369
* Escapes non-special "?" characters in a string or regex.
368
- *
370
+ *
369
371
* - For regular strings, it escapes all unescaped "?" characters by adding a backslash (`\`).
370
- * - For regex patterns (strings enclosed in `/.../`), it analyzes each "?" to determine if it has special meaning
372
+ * - For regex patterns (strings enclosed in `/.../`), it analyzes each "?" to determine if it has special meaning
371
373
* (e.g., `?` in `(abc)?`, `.*?`) or is just a literal character. Only literal "?" characters are escaped.
372
374
* @param {string } input - The input string or regex pattern.
373
375
* @returns {string } - The modified string or regex with non-special "?" characters escaped.
@@ -377,8 +379,8 @@ export class RedirectsMiddleware extends MiddlewareBase {
377
379
const isRegex = input . startsWith ( '/' ) && input . endsWith ( '/' ) ; // Check if the string is a regex
378
380
379
381
if ( ! isRegex ) {
380
- // If not a regex, escape all unescaped "?" characters
381
- return input . replace ( regexPattern , '\\?' ) ;
382
+ // If not a regex, escape all unescaped "?" characters
383
+ return input . replace ( regexPattern , '\\?' ) ;
382
384
}
383
385
384
386
// If it's a regex, analyze each "?" character
@@ -387,21 +389,21 @@ export class RedirectsMiddleware extends MiddlewareBase {
387
389
388
390
let match ;
389
391
while ( ( match = regexPattern . exec ( input ) ) !== null ) {
390
- const index = match . index ; // Position of "?" in the string
391
- const before = input . slice ( 0 , index ) . replace ( / \s + $ / , '' ) ; // Context before "?"
392
- const lastChar = before . slice ( - 1 ) ; // Last character before "?"
392
+ const index = match . index ; // Position of "?" in the string
393
+ const before = input . slice ( 0 , index ) . replace ( / \s + $ / , '' ) ; // Context before "?"
394
+ const lastChar = before . slice ( - 1 ) ; // Last character before "?"
393
395
394
- // Determine if the "?" is a special regex symbol
395
- const isSpecialRegexSymbol = / [ \. \* \+ \) \[ \] ] $ / . test ( lastChar ) ;
396
+ // Determine if the "?" is a special regex symbol
397
+ const isSpecialRegexSymbol = / [ \. \* \+ \) \[ \] ] $ / . test ( lastChar ) ;
396
398
397
- if ( isSpecialRegexSymbol ) {
398
- // If it's special, keep it as is
399
- result += input . slice ( lastIndex , index + 1 ) ;
400
- } else {
401
- // If it's not special, escape it
402
- result += input . slice ( lastIndex , index ) + '\\?' ;
403
- }
404
- lastIndex = index + 1 ;
399
+ if ( isSpecialRegexSymbol ) {
400
+ // If it's special, keep it as is
401
+ result += input . slice ( lastIndex , index + 1 ) ;
402
+ } else {
403
+ // If it's not special, escape it
404
+ result += input . slice ( lastIndex , index ) + '\\?' ;
405
+ }
406
+ lastIndex = index + 1 ;
405
407
}
406
408
407
409
// Append the remaining part of the string
0 commit comments