Skip to content

Commit

Permalink
Test loose can be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Jun 4, 2024
1 parent 01086a0 commit 578b072
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
];

/**
Expand Down
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 578b072

Please sign in to comment.