Hash test matching different from path matching
jvailius opened this issue · 1 comments
jvailius commented
Hi, does someone know if there a particular reason for this behavior: The path is (correctly I guess) not matched but the hash is.
const pattern = new URLPattern("/#/books/:id", "http://example.com");
pattern.test("http://example.com/#/books/1/page/0") // true
const pattern = new URLPattern("/books/:id", "http://example.com");
pattern.test("http://example.com/books/1/page/0") // false
Thank you.
Tested with Google Chrome 117.0.5938.149 (Official Build) (64-bit)
jeremyroman commented
/
has special treatment as a separating character in the pathname component, but not in the hash (where / has special meaning only for libraries that choose to treat it that way).
As one workaround, you can use a regex group, like so:
const pattern = new URLPattern('/#/books/:id([^/]+)', 'http://example.com');
pattern.test("http://example.com/#/books/1/page/0") // false