Comments (8)
By the way, thank you for bringing this use case to my attention. There was some discussion at TPAC about limiting the effort to only pathname for now. I plan to try to press forward with the full proposal, though.
from urlpattern.
FWIW there is an existing polyfill written on top of path-to-regexp: https://github.com/kenchris/urlpattern-polyfill/blob/main/src/index.js
I expect the final URLPattern will look at a bit different (targeting newer path-to-regexp now, etc), but its possible to do all this server-side already more or less.
from urlpattern.
The current design does support patterns for each URL component. So your first example could be expressed as:
new URLPattern({ protocol: 'https' });
Currently the design is focused on the more granular URL components and does not have an "origin" concept. You could implement your second example like:
new URLPattern({ protocol: 'https', hostname: 'example.com' });
Or by providing a "base URL" and overriding the pathname part to be a wildcard:
new URLPattern({ baseUrl: "https://example.com", pathname: "/*" });
Maybe we can add some kind of origin short hand, but I'd like to get the basics prototyped first.
Does this meet your use cases?
from urlpattern.
Yeah, this should meet the requirement! Thanks!
from urlpattern.
No problem :) I also heard feedback from people that this will be useful in server-side as well to check request URL pattern, so some people are looking forward to use this in server-side Node JS 😀
from urlpattern.
The current design does support patterns for each URL component. So your first example could be expressed as:
new URLPattern({ protocol: 'https' });Currently the design is focused on the more granular URL components and does not have an "origin" concept. You could implement your second example like:
new URLPattern({ protocol: 'https', hostname: 'example.com' });
nit: If I understand correctly this will permit https://example.com:PORT for every port, which is broader than the origin https://example.com (which is only port 443). Just mentioning this because it seems like a potential pitfall.
from urlpattern.
nit: If I understand correctly this will permit https://example.com:PORT for every port, which is broader than the origin https://example.com (which is only port 443). Just mentioning this because it seems like a potential pitfall.
That is currently correct. You would need to be more restrictive by including port: '(443)?'
if the port restriction was important.
We might want to make some "empty string matches the default port for the port" type equivalence, but I'm a bit leery of making one of the components an exception to the "gets a wildcard by default" rule.
from urlpattern.
I wrote a couple related issue:
from urlpattern.
Related Issues (20)
- Base URL inheritance gives unintuitive results HOT 21
- Consider creating a RFC for base functionality HOT 2
- Add a "using URLPattern in other APIs" section HOT 9
- Backslash escaping is required for colon before password in string syntax
- WHATWG migration HOT 5
- Attribute to show the regular expression usage. HOT 9
- Hash test matching different from path matching HOT 1
- Consider cleaning up extra markdown documents
- Custom named full-wildcard HOT 2
- Base URL and empty pathname in URLPatternInit
- Incorrect handling of base URL in URLPatternInit processing HOT 10
- Loose base URL check can crash URL parser HOT 5
- Handling of special character in hostname
- More consistent and robust segment wilcard generation
- Incorrect type in group name assignment
- "Hostname pattern is an IPv6 address" called with `null` HOT 1
- Constructor string parser has confusing result for paths containing a colon. HOT 1
- The way to integrate the API without depending on ECMAScript realm. HOT 3
- Accept URL as the match algorithm's input. HOT 4
- Opaque Host and domain encoding HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from urlpattern.