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

URLPattern doesn't match if URL ends with / #12259

Closed
ebebbington opened this issue Sep 28, 2021 · 2 comments
Closed

URLPattern doesn't match if URL ends with / #12259

ebebbington opened this issue Sep 28, 2021 · 2 comments

Comments

@ebebbington
Copy link
Contributor

See the below example:

const url = "http://localhost/coffee/2/"
const path = "/coffee/:id"
const pattern = new URLPattern({ path })
pattern.exec(url) // null

I believe it should match in this case, and could be a huge downfall for the usabillity of this 'new' API

Though in some cases, i think it does match when the url ends with /, so i think it might be quite flaky?

@lucacasonato
Copy link
Member

This is intentional spec behaviour: whatwg/urlpattern#14.

If you want to match trailing slashes, add a {/}? to the end of your pattern.

@lucacasonato
Copy link
Member

Opened an issue on MDN to clarify this in docs: mdn/content#9327

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

No branches or pull requests

2 participants