Skip to content

Commit

Permalink
Simplify non-strict regexp for "end" mode
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Aug 27, 2017
1 parent 144ff8c commit 7491a7c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,13 @@ function tokensToRegExp (tokens, keys, options) {
}
}

// In non-strict mode we allow a delimiter at the end of a match.
if (!strict) {
route += '(?:' + delimiter + '(?=' + endsWith + '))?'
}

if (end) {
route += endsWith === '$' ? endsWith : '(?=' + endsWith + ')'
if (!strict) route += '(?:' + delimiter + ')?'

route += endsWith === '$' ? '$' : '(?=' + endsWith + ')'
} else {
// In non-ending mode, we need the capturing groups to match as much as
// possible by using a positive lookahead to the end or next path segment.
if (!strict) route += '(?:' + delimiter + '(?=' + endsWith + '))?'

route += '(?=' + delimiter + '|' + endsWith + ')'
}

Expand Down

0 comments on commit 7491a7c

Please sign in to comment.