2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-30 15:24:11 +03:00

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 `#`
This commit is contained in:
Anatoly Ryabov
2018-09-04 10:53:57 +03:00
committed by Khaled Garbaya
parent 21ae22dbd3
commit 81eaa3db4c
2 changed files with 11 additions and 0 deletions
+5
View File
@@ -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;
}
+6
View File
@@ -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'};