diff --git a/src/index.spec.ts b/src/index.spec.ts index f41ed69..f807e48 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -2771,6 +2771,26 @@ const MATCH_TESTS: MatchTestSet[] = [ }, ], }, + + /** + * No loose. + */ + { + path: "/test", + options: { loose: "" }, + tests: [ + { + input: "/test", + matches: ["/test"], + expected: { path: "/test", index: 0, params: {} }, + }, + { + input: "//test", + matches: null, + expected: false, + }, + ], + }, ]; /** diff --git a/src/index.ts b/src/index.ts index fd0f9df..6615fb9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -634,10 +634,7 @@ function tokensToRegexp( } } - if (trailing) { - pattern += `(?:${stringify(data.delimiter)})${loose ? "?" : ""}`; - } - + if (trailing) pattern += `(?:${stringify(data.delimiter)})?`; pattern += end ? "$" : `(?=${escape(data.delimiter)}|$)`; return new RegExp(pattern, flags(options));