Replace escape with encodeURIComponent

Both `escape` and `unescape` have been deprecated for many years. The alternative is to use `encodeURIComponent` and it’s counterpart `decodeURIComponent`.

Since using `encodeURIComponent` on the path would produce unwanted results, I have left it unencoded.