Special character route matching
Hi there, I've been having a great time getting to know solid-start since it's matured, and so far the experience has been pretty well.
However there's one thing that's proving to quite the hurdle, and that has to do with specially crafted URLs. Currently solid-start supports various routes such as
/todos/:todoId/attachment/:attachmentId
, mapping to parameters properly, however this tends to break in some cases with special characters.
Currently I'm trying to redirect users to a solid-start website, mostly re-using an existing endpoint in the form of something like /items/234932#stock/4827
. The inclusion of the hash symbol however, seems to completely cut off anything after the part. In all honesty I'm really only interested in the last part, but whatever I can find, I can't seem to get a hold of the original request URL, before matching.
Would it be possible to intercept requests before solid handles them, using something like a custom server in nextjs, so that the URL might be able to be rewritten to fit the normal mapping schema? As of now I've tried quite a few workarounds, but nothing seems to be sticking as of yet. Any suggestions and pointers would be really appreciated!5 Replies
Thatβs html Standard. This can be used to tell the browser to scroll to an element with the ID which matches the characters after the hash.
https://developer.mozilla.org/en-US/docs/Web/API/URL/hash
MDN Web Docs
URL: hash property - Web APIs | MDN
The hash property of the URL interface is a string containing a "#" followed by the fragment identifier of the URL. If the URL does not have a fragment identifier, this property contains an empty string, "".
Hey thanks, yep totally is part of the standard, the URL parsing logic has no flaws from that point of view haha.
Problem is reality often gets messy in the details, and sometimes non-standard workarounds are needed to deal with existing systems. To fix this I'm probably going to fix it at a layer before the web server itself (reverse proxy) if possible.
When I've got something working I'll detail my workaround steps here in case anyone else runs into the same kind of issue in the future, that way they'll at least have some pointers on what's possible.
Thatβs build the in browser behaviour. Youβll need to URL.encode the id
abc#def
would become
abc%23def
Thatβs should work just fine
Yep something like that is the plan, rewrite the request URL to fit the standard schema
Hey there update for anyone reading, I've managed to resolve this at a higher layer at the nginx reverse proxy. The config uses rewriting to rewrite the url like following:
smart