From 81eaa3db4cf51bd911f98de5aa1ad130b3c55c8e Mon Sep 17 00:00:00 2001 From: Anatoly Ryabov Date: Tue, 4 Sep 2018 10:53:57 +0300 Subject: [PATCH] Fixing building url with hash mark (#1771) This commit fix building url with hash map (fragment identifier) when parameters are present: they must not be added after `#`, because client cut everything after `#` --- lib/helpers/buildURL.js | 5 +++++ test/specs/helpers/buildURL.spec.js | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/lib/helpers/buildURL.js b/lib/helpers/buildURL.js index be83cd0029..8c40e4096a 100644 --- a/lib/helpers/buildURL.js +++ b/lib/helpers/buildURL.js @@ -59,6 +59,11 @@ module.exports = function buildURL(url, params, paramsSerializer) { } if (serializedParams) { + var hashmarkIndex = url.indexOf('#'); + if (hashmarkIndex !== -1) { + url = url.slice(0, hashmarkIndex); + } + url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams; } diff --git a/test/specs/helpers/buildURL.spec.js b/test/specs/helpers/buildURL.spec.js index 83d7ba1640..b819f9d2eb 100644 --- a/test/specs/helpers/buildURL.spec.js +++ b/test/specs/helpers/buildURL.spec.js @@ -54,6 +54,12 @@ describe('helpers::buildURL', function () { })).toEqual('/foo?query=bar&start=0&length=5'); }); + it('should correct discard url hash mark', function () { + expect(buildURL('/foo?foo=bar#hash', { + query: 'baz' + })).toEqual('/foo?foo=bar&query=baz'); + }); + it('should use serializer if provided', function () { serializer = sinon.stub(); params = {foo: 'bar'};