New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking changes important to the polyfill #13
Comments
I plan to target the 1.7 version of path-to-regexp that includes You can see this by using the express route tester with versions set to 1.7.0 and options set to strict and end: https://forbeslindesay.github.io/express-route-tester/
I'm not sure what you are suggesting here. If you use the route tester above you can see that path-to-regexp does pull out named groups. It does it via a |
Oh, so that support was there in 1.7 and removed in future version? I think the support would be quite useful.
That I know, as I polyfilled it, but you added the results to So as the explainer suggested aligning with current JS regexp APIs, we should use |
But in URLPattern we have multiple patterns. You can have a I'm not sure how else to handle this to be honest. I could forbid conflicting named groups in the pathname and hostname patterns, for example, but that would not help with non-named groups where an index is used. |
For example:
|
Basically there is not a single path-to-regexp instance per URLPattern. There are multiple. One for each component of the URL. This is because our use case is to match the entire URL and not just the path which has been path-to-regexp primary goal. |
I see, that different would be nice to point out in the explainer. |
I can add that. I guess I was trying to keep the explainer focused on use cases and avoid going into too much API detail there. Hard to strike the right balance. I must admit I didn't anticipate anyone would attempt to polyfill from just the explainer. There are a lot more details about URLPattern in the design doc. It goes into both the issues you encountered here. |
Could you give me comment rights?
Also what does pattern value refer to, there are many pattern values here (pathname, password, port etc)? You mean that pathname, protocol and host ? Also what is supposed to happen if protocol is set to "https" but baseURL is say "http://google.com/maps"?
What pattern value again? You mean that "host" should be matched against ""? What is protocol is not given, should that also be "" then?
So I read this as if pathname is not given and there is no baseURL it should be "/*" Is baseURL always supposed to be an actual valid URL, or do you allow people to set o a pattern as dicussed above |
So URLPattern does pattern matching on URL components individually. If any component fails to match, then the whole match fails. All component patterns default to If you specify a The URLPattern init dictionary can then override any component pattern. For example: new URLPattern({
baseUrl: 'https://example.com/foo',
pathname: '/*.jpg'
}) Ends up with the same component patterns I listed above, but the pathname pattern is overridden to I think this will become clearer when I actually write a spec with a processing model. Also note, this conversation helped me realize there is a bug in my current design. There is currently a |
Overall I expect the API to continue to evolve a bit as I prototype things and discover issues. Sorry its still in flux. |
To extend the example above, if you did this instead: new URLPattern({
pathname: '/*.jpg'
}); Then protocol, hostname, and other components are all |
Yeah, I noticed that myself. Also it doesn't make it clear what |
I have a pretty simple polyfill (so far only for URLPattern object) here: https://github.com/kenchris/urlpattern-polyfill/blob/main/src/index.js It seems to work pretty well and makes it quite easy to play around with the API shape |
That looks great! I will try to play around with it when I get a chance. |
A couple of things I'd like to flag on the syntax, and this could be a whole different issue if that's more appropriate: The expectation of This starts to touch on #14 and other issues flagged in the repo related to hostname and other segment matching. One thing I'd probably recommend, but does make it incompatible with |
Another thing to flag with |
Let's use this issue for tracking changes that are relevant to the polyfill. Some code is starting to land in chromium. The changes you may want to update for right now are:
|
And I'm starting to add WPT tests, but I recommend waiting for this CL to land before trying to use them. It uses a separate data file of cases that should make it easier to integrate tests with other implementations/platforms. |
I'm going to close this for now. In the future I'll open issues on: |
I made a small polyfill on top of path-to-regex to play around with this and found a few differences.
First of all, something like
pathname: '/*.:imagetype(jpg|gif|png)'
doesn't work, the wildcard has to be
(.*)
instead. I do like the/*
wildcard so maybe we can just document this as an improvement.You expose named groups as
result.pathname.groups
- but JS regexp actually supports named groups now (path-to-regex doesn't use that feature) and that it exposed toresult.groups
.Basically this
could be done with regexps like:
The text was updated successfully, but these errors were encountered: