urlpattern-polyfill
urlpattern-polyfill copied to clipboard
Test url with query got wrong result
const p = new URLPattern({ pathname: "/api/Artworks/:id", baseURL: "http://localhost" })
const u = new URL("http://localhost/api/Artworks/1?a=1")
console.log(p.test(u))
This fails to match because the baseURL sets a non-variable search param pattern of empty string. With a baseURL you need to explicitly opt-in to a wildcard search pattern. Like:
const p = new URLPattern({ pathname: "/api/Artworks/:id", search: '*', baseURL: "http://localhost" })
const u = new URL("http://localhost/api/Artworks/1?a=1")
console.log(p.test(u))
Edit: I agree this is not ideal or the most ergonomic, but there are reasons it worked out this way.
Thanks for response