Skip to content

Commit

Permalink
fix(request): use WHATWG URL to encode unicode characters
Browse files Browse the repository at this point in the history
closes #82
  • Loading branch information
derevnjuk committed Apr 15, 2021
1 parent 7d7f81b commit 5bc80ee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
6 changes: 2 additions & 4 deletions src/RequestExecutor/Request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Helpers, logger } from '../Utils';
import { logger } from '../Utils';
import { URL } from 'url';
import { readFile } from 'fs';
import { extname } from 'path';
Expand Down Expand Up @@ -73,13 +73,11 @@ export class Request {
}

try {
new URL(url);
this.url = new URL(url).toString();
} catch {
throw new Error('Invalid URL.');
}

this.url = Helpers.encodeURL(url);

if (body && typeof body !== 'string') {
throw new Error('Body must be string.');
}
Expand Down
12 changes: 0 additions & 12 deletions src/Utils/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,6 @@ export class Helpers {
}, {});
}

public static encodeURL(str: string): string {
let decodedStr: string;

try {
decodedStr = decodeURI(str);
} catch {
decodedStr = str;
}

return encodeURI(decodedStr).replace(/%5B/g, '[').replace(/%5D/g, ']');
}

// It's based on https://qntm.org/cmd
private static escapeShellArgument(val: string): string {
val = `${val}`;
Expand Down

0 comments on commit 5bc80ee

Please sign in to comment.