Skip to content

Commit

Permalink
fix: URL encode formParamsToString values (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonaPaulus authored May 2, 2022
1 parent a8c75ac commit 269bf72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/app/core/utils/url-form-params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ describe('Url Form Params', () => {
)
).toMatchInlineSnapshot(`"bar=d_or_e&foo=c"`);
});

it('should url-encode the incoming val', () => {
expect(formParamsToString({ test: ['Laptops & Convertibles'] })).toMatchInlineSnapshot(
`"test=Laptops%20%26%20Convertibles"`
);
});

it('should not url-encode the given seperator', () => {
expect(formParamsToString({ test: ['Laptops & Convertibles', 'Desktop Computers'] })).toMatchInlineSnapshot(
`"test=Laptops%20%26%20Convertibles,Desktop%20Computers"`
);
});
});

describe('appendFormParamsToHttpParams', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/utils/url-form-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function formParamsToString(object: URLFormParams, separator = ','): stri
return object
? Object.entries(object)
.filter(([, value]) => Array.isArray(value) && value.length)
.map(([key, val]) => `${key}=${val.join(separator)}`)
.map(([key, val]) => `${key}=${val.map(encodeURIComponent).join(separator)}`)
.join('&')
: '';
}
Expand Down

0 comments on commit 269bf72

Please sign in to comment.