Skip to content

Commit

Permalink
Wrap patterns in non-matching group before output
Browse files Browse the repository at this point in the history
Fixes #78
  • Loading branch information
blakeembrey committed May 18, 2016
1 parent c6fafb1 commit 71d3232
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -133,7 +133,7 @@ function tokensToFunction (tokens) {
// Compile all the patterns before compilation.
for (var i = 0; i < tokens.length; i++) {
if (typeof tokens[i] === 'object') {
matches[i] = new RegExp('^' + tokens[i].pattern + '$')
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$')
}
}

Expand Down Expand Up @@ -337,7 +337,7 @@ function tokensToRegExp (tokens, options) {
route += escapeString(token)
} else {
var prefix = escapeString(token.prefix)
var capture = token.pattern
var capture = '(?:' + token.pattern + ')'

if (token.repeat) {
capture += '(?:' + prefix + capture + ')*'
Expand Down
21 changes: 21 additions & 0 deletions test.ts
Expand Up @@ -859,6 +859,27 @@ var TESTS: Test[] = [
[{ route: 'that' }, '/that']
]
],
[
'/:path(abc|xyz)*',
null,
[
{
name: 'path',
prefix: '/',
delimiter: '/',
optional: true,
repeat: true,
pattern: 'abc|xyz'
}
],
[
['/abc', ['/abc', 'abc']],
['/abc/abc', ['/abc/abc', 'abc/abc']]
],
[
[{ path: 'abc' }, '/abc']
]
],

/**
* Prefixed slashes could be omitted.
Expand Down

0 comments on commit 71d3232

Please sign in to comment.