From df6ac0bbb806033c7c7a9514ce32b03cc150b601 Mon Sep 17 00:00:00 2001 From: Tommaso Paulon Date: Thu, 31 Oct 2024 14:08:07 +0000 Subject: [PATCH] fix: allow passing a callback as paramsSerializer to buildURL --- lib/helpers/buildURL.js | 8 +++++++- test/specs/helpers/buildURL.spec.js | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/helpers/buildURL.js b/lib/helpers/buildURL.js index d769fdf4de..a17fd12c3b 100644 --- a/lib/helpers/buildURL.js +++ b/lib/helpers/buildURL.js @@ -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 */ @@ -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; diff --git a/test/specs/helpers/buildURL.spec.js b/test/specs/helpers/buildURL.spec.js index 3fccd30b56..2d166e1d7f 100644 --- a/test/specs/helpers/buildURL.spec.js +++ b/test/specs/helpers/buildURL.spec.js @@ -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'); }); });