Skip to content

Commit

Permalink
Fix invalid matching of :name* parameter (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Feb 11, 2022
1 parent b45871b commit 762bc6b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/index.spec.ts
Expand Up @@ -2593,6 +2593,39 @@ const TESTS: Test[] = [
[{ foo: "#" }, null],
],
],
/**
* https://github.com/pillarjs/path-to-regexp/issues/260
*/
[
":name*",
undefined,
[
{
name: "name",
prefix: "",
suffix: "",
modifier: "*",
pattern: "[^\\/#\\?]+?",
},
],
[["foobar", ["foobar", "foobar"]]],
[[{ name: "foobar" }, "foobar"]],
],
[
":name+",
undefined,
[
{
name: "name",
prefix: "",
suffix: "",
modifier: "+",
pattern: "[^\\/#\\?]+?",
},
],
[["foobar", ["foobar", "foobar"]]],
[[{ name: "foobar" }, "foobar"]],
],
];

/**
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Expand Up @@ -563,7 +563,11 @@ export function tokensToRegexp(
route += `(?:${prefix}(${token.pattern})${suffix})${token.modifier}`;
}
} else {
route += `(${token.pattern})${token.modifier}`;
if (token.modifier === "+" || token.modifier === "*") {
route += `((?:${token.pattern})${token.modifier})`;
} else {
route += `(${token.pattern})${token.modifier}`;
}
}
} else {
route += `(?:${prefix}${suffix})${token.modifier}`;
Expand Down

0 comments on commit 762bc6b

Please sign in to comment.