Closed kettanaito closed 3 months ago
It's also interesting that nowhere in the spec I can see any mention about group names having to be unique within the same URL component. Feel free to link that, I couldn't find it. If there is no such mention, then I'd treat this as a bug, not a feature proposal.
I also have an interest in fixing this given a bit of guidance.
@wanderview, I apologize for a direct ping, just wanted to check if this is considered a bug (which I believe it is). Thanks.
Sorry for the slow response!
Regarding the duplicated name, there is a mention here. So this is not a bug.
In comparison, path-to-regexp also doesn't support this behavior, but neither does it throw. It accepts the path syntax, just doesn't merge the values (the latest value is considered the whole value of the group):
URLPattern used to behave like this before, but it was changed to throw an error in https://github.com/whatwg/urlpattern/issues/96, and I think that direction makes sense.
Thanks for the response, @sisidovski! Got it. Will have to make it a breaking change on my end then. Closing as not a bug.
What problem are you trying to solve?
I'd like to declare a pattern like this:
Right now,
URLPattern
throws an error on such a path pattern:What solutions exist today?
None, if speaking of the solutions provided by
URLPattern
.62 can be a related issue to this (supporting multiple same-named groups within the same URL component will solve some of the concerns behind exposing the root-level
result.groups
).How would you solve it?
Allow the same URL component to have multiple groups with the same name.
If multiple groups with the same name are present within the same URL component, their matches are merged into an array, where the index represents the match occurrence.
Merging the values into an array also helps disambiguate between complex matches, like repeating groups, and multiple same-named groups matches:
Anything else?
In comparison,
path-to-regexp
also doesn't support this behavior, but neither does it throw. It accepts the path syntax, just doesn't merge the values (the latest value is considered the whole value of the group):This also means that
URLPattern
has this as a difference between itself andpath-to-regexp
but it's not mentioned in this section: