sanitize-pathname
v0.1.7
Published
Sanitize the `pathname` segment of the URL like a browser does.
Readme
sanitize-pathname
Sanitize the pathname segment of the URL like a browser does.
This is useful for web frameworks/routers to do before registering a new route so that it matches what the web server will give you (for example, Request.url in Bun/Deno). Here's what it does:
- Run
encodeURIComponentexcept for %, [, ], !, *, ', (, ), ;, :, @, &, =, +, $, ,, /, ?, #, - - Replace all backslashes (\) with forward slashes (/)
- Add a forward slash at the beginning if there's none
- Resolve ".." and "." segments
