@@ -341,8 +341,6 @@ function tokensToRegExp (tokens, keys, options) {
341
341
var strict = options . strict
342
342
var end = options . end !== false
343
343
var route = ''
344
- var lastToken = tokens [ tokens . length - 1 ]
345
- var endsWithSlash = typeof lastToken === 'string' && / \/ $ / . test ( lastToken )
346
344
347
345
// Iterate over the tokens and create our regexp string.
348
346
for ( var i = 0 ; i < tokens . length ; i ++ ) {
@@ -374,20 +372,23 @@ function tokensToRegExp (tokens, keys, options) {
374
372
}
375
373
}
376
374
375
+ var delimiter = escapeString ( options . delimiter || '/' )
376
+ var endsWithDelimiter = route . slice ( - delimiter . length ) === delimiter
377
+
377
378
// In non-strict mode we allow a slash at the end of match. If the path to
378
379
// match already ends with a slash, we remove it for consistency. The slash
379
380
// is valid at the end of a path match, not in the middle. This is important
380
381
// in non-ending mode, where "/test/" shouldn't match "/test//route".
381
382
if ( ! strict ) {
382
- route = ( endsWithSlash ? route . slice ( 0 , - 2 ) : route ) + '(?:\\/ (?=$))?'
383
+ route = ( endsWithDelimiter ? route . slice ( 0 , - delimiter . length ) : route ) + '(?:' + delimiter + ' (?=$))?'
383
384
}
384
385
385
386
if ( end ) {
386
387
route += '$'
387
388
} else {
388
389
// In non-ending mode, we need the capturing groups to match as much as
389
390
// possible by using a positive lookahead to the end or next path segment.
390
- route += strict && endsWithSlash ? '' : '(?=\\/ |$)'
391
+ route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + ' |$)'
391
392
}
392
393
393
394
return attachKeys ( new RegExp ( '^' + route , flags ( options ) ) , keys )
0 commit comments