I'd recommend getting rid of this regex, and replacing it with a roundtrip through `require("url").parse(string)` which will parse a URL to make sure it's valid, including escaping characters, check protocol and such, then call `url.format()`,  then format it as a proper URL.

But maybe we should refactor this out into a separate module and add some tests first...