Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
fix(converter): interpolate encoded query string params (#12)
Browse files Browse the repository at this point in the history
closes #11
  • Loading branch information
derevnjuk authored Jul 17, 2020
1 parent 5ee32b6 commit fd367bc
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/converter/DefaultConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,12 @@ export class DefaultConverter implements Converter {
}

const urlObject: UrlObject = this.prepareUrl(value);
const urlString: string = envParser.parse(format(urlObject));

return this.normalizeUrl(urlString);
let urlString: string = decodeURI(format(urlObject));

urlString = envParser.parse(urlString);

return this.normalizeUrl(encodeURI(urlString));
}

private normalizeUrl(urlString: string): string {
Expand Down Expand Up @@ -508,7 +511,7 @@ export class DefaultConverter implements Converter {
.join('/')
: url.path;

const query = this.prepareQueries(url, urlParser);
const query = this.prepareQueries(url);

let auth = '';

Expand All @@ -528,15 +531,12 @@ export class DefaultConverter implements Converter {
};
}

private prepareQueries(
url: Postman.Url,
urlParser: VariableParser
): ParsedUrlQuery | undefined {
private prepareQueries(url: Postman.Url): ParsedUrlQuery | undefined {
return Array.isArray(url.query)
? Object.fromEntries(
url.query.map((x: Postman.QueryParam) => [
(x.key ?? '').trim(),
!x.value ? urlParser.parse(x.key) : x.value
(x.value ?? '').trim()
])
)
: undefined;
Expand All @@ -548,14 +548,10 @@ export class DefaultConverter implements Converter {
): Har.QueryString[] {
let query: ParsedUrlQuery | undefined;

const urlParser: VariableParser = this.parserFactory.createUrlVariableParser(
typeof url !== 'string' ? url.variable : []
);

if (typeof url === 'string') {
query = parse(url, true).query;
} else {
query = this.prepareQueries(url, urlParser);
query = this.prepareQueries(url);
}

if (!query) {
Expand Down

0 comments on commit fd367bc

Please sign in to comment.