Skip to content

Commit 762bc6b

Browse files
authored
Fix invalid matching of :name* parameter (#261)
1 parent b45871b commit 762bc6b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/index.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,39 @@ const TESTS: Test[] = [
25932593
[{ foo: "#" }, null],
25942594
],
25952595
],
2596+
/**
2597+
* https://github.com/pillarjs/path-to-regexp/issues/260
2598+
*/
2599+
[
2600+
":name*",
2601+
undefined,
2602+
[
2603+
{
2604+
name: "name",
2605+
prefix: "",
2606+
suffix: "",
2607+
modifier: "*",
2608+
pattern: "[^\\/#\\?]+?",
2609+
},
2610+
],
2611+
[["foobar", ["foobar", "foobar"]]],
2612+
[[{ name: "foobar" }, "foobar"]],
2613+
],
2614+
[
2615+
":name+",
2616+
undefined,
2617+
[
2618+
{
2619+
name: "name",
2620+
prefix: "",
2621+
suffix: "",
2622+
modifier: "+",
2623+
pattern: "[^\\/#\\?]+?",
2624+
},
2625+
],
2626+
[["foobar", ["foobar", "foobar"]]],
2627+
[[{ name: "foobar" }, "foobar"]],
2628+
],
25962629
];
25972630

25982631
/**

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,11 @@ export function tokensToRegexp(
563563
route += `(?:${prefix}(${token.pattern})${suffix})${token.modifier}`;
564564
}
565565
} else {
566-
route += `(${token.pattern})${token.modifier}`;
566+
if (token.modifier === "+" || token.modifier === "*") {
567+
route += `((?:${token.pattern})${token.modifier})`;
568+
} else {
569+
route += `(${token.pattern})${token.modifier}`;
570+
}
567571
}
568572
} else {
569573
route += `(?:${prefix}${suffix})${token.modifier}`;

0 commit comments

Comments
 (0)