You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm testing out the URLPattern in Chrome canary against the test suite I use for Vue Router and I found that repeated groups (/:id+ and /:id*) are not put into an array when extracted:
constpath='/:id+'constpathToTest='/a/b/c'constpattern=newURLPattern(path,'http://e.e')constmatch=pattern.exec(pathToTest,'http://e.e')console.assert(JSON.stringify(match?.pathname.groups)==='["a","b","c"]',`Got ${JSON.stringify(match?.pathname.groups)} instead of array`)
This will output:
Assertion failed: Got {"id":"a/b/c"} instead of array
While it's easy to make this work by calling .split('/'), I think id should be an array because its modifier is a repeatable one.
The text was updated successfully, but these errors were encountered:
posva
changed the title
Repeated params are not split into an array
Repeated groups are not split into an array
Nov 10, 2021
I think this one is working as intended. Its behavior inherited from path-to-regexp.
Also, its unclear to me how to implement this in the general sense. Consider that a repeated modifier might be applied to something without a prefix; e.g. foo{:g}+bar. Also consider that :g is a non-greedy match meaning that "each group" would match as few characters as possible. So if we split this into an array, then matching against foobazbar would result in a g array where each letter is a separate array index like ['b', 'a', 'z']. This doesn't seem expected or desirable to me.
I think I would prefer to leave it to external code to do the splitting in a way that made sense to them for now. If it becomes super common then maybe we could adopt and option to auto-split on a given divider or something in the future.
I see, to me, repeatable groups can only be between / e.g: /:id+ but never /a-:id+-b, so I never faced anything like foo:g+bar. Semantically speaking I do expect a list for a repeatable group though but I think that's maybe only from the router perspective. So it would make sense to keep this behavior in the context of a pattern
To me this reinforces the need of #147 in order to apply custom transformations to groups
Hello, I'm testing out the URLPattern in Chrome canary against the test suite I use for Vue Router and I found that repeated groups (
/:id+
and/:id*
) are not put into an array when extracted:This will output:
While it's easy to make this work by calling
.split('/')
, I thinkid
should be an array because its modifier is a repeatable one.The text was updated successfully, but these errors were encountered: