@@ -341,8 +341,6 @@ function tokensToRegExp (tokens, keys, options) {
341341 var strict = options . strict
342342 var end = options . end !== false
343343 var route = ''
344- var lastToken = tokens [ tokens . length - 1 ]
345- var endsWithSlash = typeof lastToken === 'string' && / \/ $ / . test ( lastToken )
346344
347345 // Iterate over the tokens and create our regexp string.
348346 for ( var i = 0 ; i < tokens . length ; i ++ ) {
@@ -374,20 +372,23 @@ function tokensToRegExp (tokens, keys, options) {
374372 }
375373 }
376374
375+ var delimiter = escapeString ( options . delimiter || '/' )
376+ var endsWithDelimiter = route . slice ( - delimiter . length ) === delimiter
377+
377378 // In non-strict mode we allow a slash at the end of match. If the path to
378379 // match already ends with a slash, we remove it for consistency. The slash
379380 // is valid at the end of a path match, not in the middle. This is important
380381 // in non-ending mode, where "/test/" shouldn't match "/test//route".
381382 if ( ! strict ) {
382- route = ( endsWithSlash ? route . slice ( 0 , - 2 ) : route ) + '(?:\\/ (?=$))?'
383+ route = ( endsWithDelimiter ? route . slice ( 0 , - delimiter . length ) : route ) + '(?:' + delimiter + ' (?=$))?'
383384 }
384385
385386 if ( end ) {
386387 route += '$'
387388 } else {
388389 // In non-ending mode, we need the capturing groups to match as much as
389390 // possible by using a positive lookahead to the end or next path segment.
390- route += strict && endsWithSlash ? '' : '(?=\\/ |$)'
391+ route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + ' |$)'
391392 }
392393
393394 return attachKeys ( new RegExp ( '^' + route , flags ( options ) ) , keys )
0 commit comments