Skip to content

Commit edca349

Browse files
committed
Wrap patterns in non-matching group before output (#79)
1 parent c6fafb1 commit edca349

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function tokensToFunction (tokens) {
133133
// Compile all the patterns before compilation.
134134
for (var i = 0; i < tokens.length; i++) {
135135
if (typeof tokens[i] === 'object') {
136-
matches[i] = new RegExp('^' + tokens[i].pattern + '$')
136+
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$')
137137
}
138138
}
139139

@@ -337,7 +337,7 @@ function tokensToRegExp (tokens, options) {
337337
route += escapeString(token)
338338
} else {
339339
var prefix = escapeString(token.prefix)
340-
var capture = token.pattern
340+
var capture = '(?:' + token.pattern + ')'
341341

342342
if (token.repeat) {
343343
capture += '(?:' + prefix + capture + ')*'

test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,35 @@ var TESTS: Test[] = [
859859
[{ route: 'that' }, '/that']
860860
]
861861
],
862+
[
863+
'/:path(abc|xyz)*',
864+
null,
865+
[
866+
{
867+
name: 'path',
868+
prefix: '/',
869+
delimiter: '/',
870+
optional: true,
871+
repeat: true,
872+
pattern: 'abc|xyz'
873+
}
874+
],
875+
[
876+
['/abc', ['/abc', 'abc']],
877+
['/abc/abc', ['/abc/abc', 'abc/abc']],
878+
['/xyz/xyz', ['/xyz/xyz', 'xyz/xyz']],
879+
['/abc/xyz', ['/abc/xyz', 'abc/xyz']],
880+
['/abc/xyz/abc/xyz', ['/abc/xyz/abc/xyz', 'abc/xyz/abc/xyz']],
881+
['/xyzxyz', null]
882+
],
883+
[
884+
[{ path: 'abc' }, '/abc'],
885+
[{ path: ['abc', 'xyz'] }, '/abc/xyz'],
886+
[{ path: ['xyz', 'abc', 'xyz'] }, '/xyz/abc/xyz'],
887+
[{ path: 'abc123' }, null],
888+
[{ path: 'abcxyz' }, null]
889+
]
890+
],
862891

863892
/**
864893
* Prefixed slashes could be omitted.

0 commit comments

Comments
 (0)