diff --git a/src/index.spec.ts b/src/index.spec.ts index 168a410..a4cae6b 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -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"]], + ], ]; /** diff --git a/src/index.ts b/src/index.ts index 05c8464..a419ae6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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}`;