Skip to content
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

consider matching structured input #27

Closed
wanderview opened this issue Nov 17, 2020 · 2 comments
Closed

consider matching structured input #27

wanderview opened this issue Nov 17, 2020 · 2 comments
Labels

Comments

@wanderview
Copy link
Member

Sometimes a developer may only care about matching a part of the URL; e.g. just against pathname. The plan of record to support this is:

let pattern = new URLPattern({ pathname: "/foo/bar/*" });

This matches the pathname, but all other URL components are wildcards.

This mostly works for the use case, but is still awkward to use since URLPattern.match() requires parseable full URLs to be passed in. For example:

const input = "/foo/bar/baz";

// fails due to invalid input
pattern.match(input);

// awkward and expensive, but works
pattern.match(new URL(input, self.location).href);

To make this more ergonomic we could allow URLPattern.match() to accept structured input:

pattern.match({ pathname: input });

This allows the developer to indicate they only have a pathname. The other components of the URL are unknown and will only match if the pattern has a wildcard specified for the component.

@wanderview
Copy link
Member Author

I've included this in the prototype and its working well. Marking decided.

@wanderview
Copy link
Member Author

This is now codified in the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant