Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit e2b1fff

Browse files
committed
use custom paramsSerializer for oauth1 requestData
1 parent a7281c8 commit e2b1fff

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

dist/axios.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ function removeSearchFromUrl(config) {
3232
config.url = url.toString(); // if ends with ? should be okay, but could be cleaner
3333
}
3434
}
35+
// this fixes query strings with spaces in them causing issues when signing
36+
// XXX https://github.com/axios/axios/pull/2563
37+
function paramsSerializer(p) {
38+
const encodeKey = (k) => {
39+
return encodeURIComponent(k)
40+
.replace(/%40/gi, '@')
41+
.replace(/%3A/gi, ':')
42+
.replace(/%24/g, '$')
43+
.replace(/%2C/gi, ',')
44+
.replace(/%20/g, '+')
45+
.replace(/%5B/gi, '[')
46+
.replace(/%5D/gi, ']');
47+
};
48+
return Object.keys(p).map(k => encodeKey(k) + '=' + encodeURIComponent(p[k])).join('&');
49+
}
50+
;
3551
// XXX warn about mutating config object... or clone?
3652
async function default_1(step, config, signConfig) {
3753
cleanObject(config.headers);
@@ -45,7 +61,7 @@ async function default_1(step, config, signConfig) {
4561
const { oauthSignerUri, token } = signConfig;
4662
const requestData = {
4763
method: config.method || "get",
48-
url: buildURL(config.url, config.params),
64+
url: buildURL(config.url, config.params, paramsSerializer),
4965
data: config.data,
5066
};
5167
const payload = {

lib/axios.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ function removeSearchFromUrl(config: AxiosRequestConfig) {
3131
}
3232
}
3333

34+
// this fixes query strings with spaces in them causing issues when signing
35+
// XXX https://github.com/axios/axios/pull/2563
36+
function paramsSerializer(p: any) {
37+
const encodeKey = (k: string) => {
38+
return encodeURIComponent(k)
39+
.replace(/%40/gi, '@')
40+
.replace(/%3A/gi, ':')
41+
.replace(/%24/g, '$')
42+
.replace(/%2C/gi, ',')
43+
.replace(/%20/g, '+')
44+
.replace(/%5B/gi, '[')
45+
.replace(/%5D/gi, ']')
46+
}
47+
return Object.keys(p).map(k => encodeKey(k) + '=' + encodeURIComponent(p[k])).join('&')
48+
};
49+
3450
// XXX warn about mutating config object... or clone?
3551
export default async function(step: any, config: AxiosRequestConfig, signConfig?: any) {
3652
cleanObject(config.headers)
@@ -44,7 +60,7 @@ export default async function(step: any, config: AxiosRequestConfig, signConfig?
4460
const {oauthSignerUri, token} = signConfig
4561
const requestData = {
4662
method: config.method || "get",
47-
url: buildURL(config.url, config.params), // build url as axios will
63+
url: buildURL(config.url, config.params, paramsSerializer), // build url as axios will
4864
data: config.data,
4965
}
5066
const payload = {

0 commit comments

Comments
 (0)