Skip to content

Commit

Permalink
fix: allow passing a callback as paramsSerializer to buildURL (#6680)
Browse files Browse the repository at this point in the history
* fix: allow passing a callback as paramsSerializer to buildURL

* fix: add missing semicolon
  • Loading branch information
guuido authored Nov 12, 2024
1 parent df956d1 commit eac4619
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/helpers/buildURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function encode(val) {
*
* @param {string} url The base of the url (e.g., http://www.google.com)
* @param {object} [params] The params to be appended
* @param {?object} options
* @param {?(object|Function)} options
*
* @returns {string} The formatted url
*/
Expand All @@ -38,6 +38,12 @@ export default function buildURL(url, params, options) {

const _encode = options && options.encode || encode;

if (utils.isFunction(options)) {
options = {
serialize: options
};
}

const serializeFn = options && options.serialize;

let serializedParams;
Expand Down
7 changes: 7 additions & 0 deletions test/specs/helpers/buildURL.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,12 @@ describe('helpers::buildURL', function () {
};

expect(buildURL('/foo', params, options)).toEqual('/foo?rendered');

const customSerializer = (thisParams) => {
expect(thisParams).toEqual(params);
return "rendered"
};

expect(buildURL('/foo', params, customSerializer)).toEqual('/foo?rendered');
});
});

0 comments on commit eac4619

Please sign in to comment.