Skip to content

Commit bdb7d76

Browse files
Adding baseURL to be used in getUri(), also removing question mark trimming since there seems to be no obvious reason for it. (#3737)
Co-authored-by: Jay <[email protected]>
1 parent 195c8e5 commit bdb7d76

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

Diff for: lib/core/Axios.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var buildURL = require('../helpers/buildURL');
55
var InterceptorManager = require('./InterceptorManager');
66
var dispatchRequest = require('./dispatchRequest');
77
var mergeConfig = require('./mergeConfig');
8+
var buildFullPath = require('./buildFullPath');
89
var validator = require('../helpers/validator');
910

1011
var validators = validator.validators;
@@ -119,7 +120,8 @@ Axios.prototype.request = function request(configOrUrl, config) {
119120

120121
Axios.prototype.getUri = function getUri(config) {
121122
config = mergeConfig(this.defaults, config);
122-
return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
123+
var fullPath = buildFullPath(config.baseURL, config.url);
124+
return buildURL(fullPath, config.params, config.paramsSerializer);
123125
};
124126

125127
// Provide aliases for supported request methods

Diff for: test/specs/api.spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ describe('static api', function () {
4242
expect(typeof axios.isCancel).toEqual('function');
4343
});
4444

45+
it('should have getUri method', function() {
46+
expect(typeof axios.getUri).toEqual('function');
47+
});
48+
4549
it('should have isAxiosError properties', function () {
4650
expect(typeof axios.isAxiosError).toEqual('function');
4751
});

Diff for: test/specs/instance.spec.js

+37
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('instance', function () {
1919
'isCancel',
2020
'all',
2121
'spread',
22+
'getUri',
2223
'isAxiosError',
2324
'VERSION',
2425
'default'].indexOf(prop) > -1) {
@@ -112,4 +113,40 @@ describe('instance', function () {
112113
}, 100);
113114
});
114115
});
116+
117+
it('should have getUri on the instance', function() {
118+
var instance = axios.create({
119+
baseURL: 'https://api.example.com'
120+
});
121+
var options = {
122+
url: 'foo/bar',
123+
params: {
124+
name: 'axios'
125+
}
126+
};
127+
expect(instance.getUri(options)).toBe('https://api.example.com/foo/bar?name=axios');
128+
});
129+
130+
it('should correctly build url without baseURL', function () {
131+
var instance = axios.create();
132+
var options = {
133+
url: 'foo/bar?foo=bar',
134+
params: {
135+
name: 'axios'
136+
}
137+
};
138+
expect(instance.getUri(options)).toBe('foo/bar?foo=bar&name=axios');
139+
});
140+
141+
it('should correctly discard url hash mark', function () {
142+
var instance = axios.create();
143+
var options = {
144+
baseURL: 'https://api.example.com',
145+
url: 'foo/bar?foo=bar#hash',
146+
params: {
147+
name: 'axios'
148+
}
149+
};
150+
expect(instance.getUri(options)).toBe('https://api.example.com/foo/bar?foo=bar&name=axios');
151+
});
115152
});

0 commit comments

Comments
 (0)