diff --git a/lib/decode_url.ts b/lib/decode_url.ts index 6859dc9e..6c976baa 100644 --- a/lib/decode_url.ts +++ b/lib/decode_url.ts @@ -3,7 +3,11 @@ import { parse, format } from 'url'; import { unescape } from 'querystring'; const decodeURL = (str: string) => { - if (parse(str).protocol) { + const index = str.indexOf(':'); + if (index < 0) { + return unescape(str); + } + if (parse(str.slice(0, index + 1)).protocol) { const parsed = new URL(str); // Exit if input is a data url diff --git a/lib/encode_url.ts b/lib/encode_url.ts index 95949f61..a6f409a0 100644 --- a/lib/encode_url.ts +++ b/lib/encode_url.ts @@ -3,7 +3,11 @@ import { parse, format } from 'url'; import { unescape } from 'querystring'; const encodeURL = (str: string) => { - if (parse(str).protocol) { + const index = str.indexOf(':'); + if (index < 0) { + return encodeURI(unescape(str)); + } + if (parse(str.slice(0, index + 1)).protocol) { const parsed = new URL(str); // Exit if input is a data url