diff --git a/src/path-to-regex-modified.ts b/src/path-to-regex-modified.ts index 62d606e..3018159 100644 --- a/src/path-to-regex-modified.ts +++ b/src/path-to-regex-modified.ts @@ -655,7 +655,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}`; diff --git a/urlpatterntestdata.json b/urlpatterntestdata.json index 4f228e9..b952773 100644 --- a/urlpatterntestdata.json +++ b/urlpatterntestdata.json @@ -2253,6 +2253,48 @@ "pattern": [{ "pathname": "/foo" }, "https://example.com" ], "expected_obj": "error" }, + { + "pattern": [{ "pathname": ":name*" }], + "inputs": [{ "pathname": "foobar" }], + "expected_match": { + "pathname": { "input": "foobar", "groups": { "name": "foobar" }} + } + }, + { + "pattern": [{ "pathname": ":name+" }], + "inputs": [{ "pathname": "foobar" }], + "expected_match": { + "pathname": { "input": "foobar", "groups": { "name": "foobar" }} + } + }, + { + "pattern": [{ "pathname": ":name" }], + "inputs": [{ "pathname": "foobar" }], + "expected_match": { + "pathname": { "input": "foobar", "groups": { "name": "foobar" }} + } + }, + { + "pattern": [{ "protocol": ":name*" }], + "inputs": [{ "protocol": "foobar" }], + "expected_match": { + "protocol": { "input": "foobar", "groups": { "name": "foobar" }} + } + }, + { + "pattern": [{ "protocol": ":name+" }], + "inputs": [{ "protocol": "foobar" }], + "expected_match": { + "protocol": { "input": "foobar", "groups": { "name": "foobar" }} + } + }, + { + "pattern": [{ "protocol": ":name" }], + "inputs": [{ "protocol": "foobar" }], + "expected_match": { + "protocol": { "input": "foobar", "groups": { "name": "foobar" }} + } + }, { "pattern": [{}], "inputs": ["https://example.com/"],