22Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
33const axios_1 = require ( "axios" ) ;
44const buildURL = require ( "axios/lib/helpers/buildURL" ) ;
5+ const querystring = require ( "querystring" ) ;
56const utils_1 = require ( "./utils" ) ;
67function cleanObject ( o ) {
78 for ( const k in o || { } ) {
@@ -32,22 +33,15 @@ function removeSearchFromUrl(config) {
3233 config . url = url . toString ( ) ; // if ends with ? should be okay, but could be cleaner
3334 }
3435}
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 ( / % 4 0 / gi, '@' )
41- . replace ( / % 3 A / gi, ':' )
42- . replace ( / % 2 4 / g, '$' )
43- . replace ( / % 2 C / gi, ',' )
44- . replace ( / % 2 0 / g, '+' )
45- . replace ( / % 5 B / gi, '[' )
46- . replace ( / % 5 D / gi, ']' ) ;
47- } ;
48- return Object . keys ( p ) . map ( k => encodeKey ( k ) + '=' + encodeURIComponent ( p [ k ] ) ) . join ( '&' ) ;
36+ // https://github.com/ttezel/twit/blob/master/lib/helpers.js#L11
37+ function oauth1ParamsSerializer ( p ) {
38+ return querystring . stringify ( p )
39+ . replace ( / \! / g, "%21" )
40+ . replace ( / \' / g, "%27" )
41+ . replace ( / \( / g, "%28" )
42+ . replace ( / \) / g, "%29" )
43+ . replace ( / \* / g, "%2A" ) ;
4944}
50- ;
5145// XXX warn about mutating config object... or clone?
5246async function default_1 ( step , config , signConfig ) {
5347 cleanObject ( config . headers ) ;
@@ -61,9 +55,10 @@ async function default_1(step, config, signConfig) {
6155 const { oauthSignerUri, token } = signConfig ;
6256 const requestData = {
6357 method : config . method || "get" ,
64- url : buildURL ( config . url , config . params , paramsSerializer ) ,
58+ url : buildURL ( config . url , config . params , oauth1ParamsSerializer ) ,
6559 data : config . data ,
6660 } ;
61+ config . paramsSerializer = oauth1ParamsSerializer ;
6762 const payload = {
6863 requestData,
6964 token,
0 commit comments