How could I totally sanitize an URL using Javascript?
In my app, I’m using several user-based url fields, and I want to be sure that most of URLs can pass, but any URL preparing an injection or DOMXSS injection ends up useless.
I’ve already tried a simple solution with a RegExp but have no idea if this will cover all the possible cases.
function sanitizeUrl(url: any) {
return url.replace(new RegExp("[^-A-Za-z0-9+&@#/%?=~_|!:,.;()]"), " ")
}