axios 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // TypeScript Version: 4.1
2
2
  type HeaderValue = string | string[] | number | boolean;
3
3
 
4
- type AxiosHeaders = Record<string, HeaderValue | Record<Method & CommonHeaders, HeaderValue>>;
4
+ type AxiosHeaders = Record<string, HeaderValue | Record<string, HeaderValue>>;
5
5
 
6
6
  type MethodsHeaders = {
7
7
  [Key in Method as Lowercase<Key>]: AxiosHeaders;
@@ -86,6 +86,7 @@ export interface TransitionalOptions {
86
86
 
87
87
  export interface GenericAbortSignal {
88
88
  aborted: boolean;
89
+ readonly reason?: unknown;
89
90
  onabort: ((...args: any) => any) | null;
90
91
  addEventListener: (...args: any) => any;
91
92
  removeEventListener: (...args: any) => any;
@@ -168,6 +169,7 @@ export interface AxiosRequestConfig<D = any> {
168
169
  cancelToken?: CancelToken;
169
170
  decompress?: boolean;
170
171
  transitional?: TransitionalOptions;
172
+ captureCallerStack?: boolean;
171
173
  signal?: GenericAbortSignal;
172
174
  insecureHTTPParser?: boolean;
173
175
  env?: {
@@ -241,6 +243,7 @@ export class AxiosError<T = unknown, D = any> extends Error {
241
243
  }
242
244
 
243
245
  export class CanceledError<T> extends AxiosError<T> {
246
+ reason?: unknown;
244
247
  }
245
248
 
246
249
  export type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
@@ -251,6 +254,7 @@ export interface CancelStatic {
251
254
 
252
255
  export interface Cancel {
253
256
  message: string | undefined;
257
+ reason?: unknown;
254
258
  }
255
259
 
256
260
  export interface Canceler {
@@ -15,12 +15,13 @@ var zlib = require('zlib');
15
15
  var VERSION = require('./../env/data').version;
16
16
  var transitionalDefaults = require('../defaults/transitional');
17
17
  var AxiosError = require('../core/AxiosError');
18
- var CanceledError = require('../cancel/CanceledError');
18
+ var canceledErrorFromSignal = require('../cancel/fromSignal');
19
19
  var platform = require('../platform');
20
20
  var fromDataURI = require('../helpers/fromDataURI');
21
21
  var stream = require('stream');
22
22
  var estimateDataURLDecodedBytes = require('../helpers/estimateDataURLDecodedBytes.js');
23
23
  var shouldBypassProxy = require('../helpers/shouldBypassProxy');
24
+ var getDirectAgent = require('../helpers/getDirectAgent');
24
25
 
25
26
  var isHttps = /https:?/;
26
27
 
@@ -28,15 +29,39 @@ var supportedProtocols = platform.protocols.map(function(protocol) {
28
29
  return protocol + ':';
29
30
  });
30
31
 
31
- function dispatchBeforeRedirect(options) {
32
+ function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
33
+ var sameOrigin = false;
34
+ try {
35
+ sameOrigin = new url.URL(requestDetails.url).origin === new url.URL(options.href).origin;
36
+ } catch (err) {
37
+ // Leave the comparison false when either URL is unavailable.
38
+ }
39
+ if (!sameOrigin) {
40
+ Object.keys(options.headers).forEach(function(header) {
41
+ if (/^(authorization|cookie)$/i.test(header)) {
42
+ delete options.headers[header];
43
+ }
44
+ });
45
+ delete options.auth;
46
+ }
32
47
  if (options.beforeRedirects.proxy) {
33
48
  options.beforeRedirects.proxy(options);
34
49
  }
50
+ if (options.beforeRedirects.direct) {
51
+ options.beforeRedirects.direct(options);
52
+ }
35
53
  if (options.beforeRedirects.config) {
36
54
  options.beforeRedirects.config(options);
37
55
  }
38
56
  }
39
57
 
58
+ function setDirectAgent(options, httpAgent, httpsAgent) {
59
+ var secure = isHttps.test(options.protocol);
60
+ var agent = getDirectAgent(secure ? httpsAgent : httpAgent, secure ? https : http);
61
+ options.agent = agent;
62
+ options.agents[secure ? 'https' : 'http'] = agent;
63
+ }
64
+
40
65
  function removeProxyAuthorization(headers) {
41
66
  Object.keys(headers).forEach(function removeHeader(header) {
42
67
  if (header.toLowerCase() === 'proxy-authorization') {
@@ -125,6 +150,43 @@ function checkSocketPath(config) {
125
150
  return null;
126
151
  }
127
152
 
153
+ /**
154
+ * Normalize a configured HTTP(S) proxy protocol to the `scheme:` form Node expects.
155
+ *
156
+ * `AxiosProxyConfig.protocol` is documented (and typed) as a bare scheme such
157
+ * as `'http'`, but the value is handed straight to `http.request` as
158
+ * `options.protocol`, where it is compared verbatim against the agent's own
159
+ * `protocol`. A missing colon therefore made every documented proxy config
160
+ * fail with `ERR_ASSERTION: protocol mismatch`. Schemes are case-insensitive,
161
+ * so fold to lower case as well.
162
+ *
163
+ * @param {*} protocol The configured proxy protocol
164
+ * @returns {string|undefined} The normalized protocol, or undefined for non-strings or an empty string
165
+ * @throws {AxiosError} If a non-empty string is not an HTTP(S) protocol
166
+ */
167
+ function normalizeProxyProtocol(protocol) {
168
+ if (typeof protocol !== 'string' || protocol === '') {
169
+ return undefined;
170
+ }
171
+
172
+ var normalized = protocol.trim().toLowerCase();
173
+
174
+ if (normalized === 'http' || normalized === 'https') {
175
+ return normalized + ':';
176
+ }
177
+
178
+ if (normalized === 'http:' || normalized === 'https:') {
179
+ return normalized;
180
+ }
181
+
182
+ // Never infer a transport from an explicitly invalid string: an HTTP target
183
+ // could otherwise send HTTPS proxy credentials over a plaintext connection.
184
+ throw new AxiosError(
185
+ 'proxy.protocol must be http or https',
186
+ AxiosError.ERR_BAD_OPTION_VALUE
187
+ );
188
+ }
189
+
128
190
  /**
129
191
  *
130
192
  * @param {http.ClientRequestArgs} options
@@ -147,6 +209,11 @@ function setProxy(options, configProxy, location) {
147
209
  removeProxyAuthorization(options.headers);
148
210
  }
149
211
  if (proxy) {
212
+ // Validate before adding proxy credentials or configuring a connection.
213
+ var proxyProtocol = normalizeProxyProtocol(
214
+ utils.hasOwnProperty(proxy, 'protocol') ? proxy.protocol : undefined
215
+ );
216
+
150
217
  // Basic proxy authorization
151
218
  var proxyAuth = utils.hasOwnProperty(proxy, 'auth')
152
219
  ? proxy.auth
@@ -178,8 +245,11 @@ function setProxy(options, configProxy, location) {
178
245
  options.host = proxy.host;
179
246
  options.port = proxy.port;
180
247
  options.path = location;
181
- if (proxy.protocol) {
182
- options.protocol = proxy.protocol;
248
+
249
+ // Preserve the target protocol when no normalized proxy protocol is supplied.
250
+ // Defaulting to HTTP here could downgrade an existing HTTPS proxy connection.
251
+ if (proxyProtocol) {
252
+ options.protocol = proxyProtocol;
183
253
  }
184
254
  }
185
255
 
@@ -272,6 +342,18 @@ module.exports = function httpAdapter(config) {
272
342
  throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
273
343
  }
274
344
 
345
+ // Check bytes before converting the result to text or a stream.
346
+ if (config.maxContentLength > -1 &&
347
+ (responseType === 'blob' ? convertedData.size : convertedData.length) > config.maxContentLength) {
348
+ return reject(
349
+ new AxiosError(
350
+ 'maxContentLength size of ' + config.maxContentLength + ' exceeded',
351
+ AxiosError.ERR_BAD_RESPONSE,
352
+ config
353
+ )
354
+ );
355
+ }
356
+
275
357
  if (responseType === 'text') {
276
358
  convertedData = convertedData.toString(responseEncoding);
277
359
 
@@ -406,6 +488,9 @@ module.exports = function httpAdapter(config) {
406
488
  reject(customErr);
407
489
  }
408
490
 
491
+ var configProxy = utils.hasOwnProperty(config, 'proxy') ? config.proxy : undefined;
492
+ var httpAgent = config.httpAgent;
493
+ var httpsAgent = config.httpsAgent;
409
494
  var options = {
410
495
  path: buildURL(
411
496
  parsed.path,
@@ -414,11 +499,15 @@ module.exports = function httpAdapter(config) {
414
499
  ).replace(/^\?/, ''),
415
500
  method: method,
416
501
  headers: headers,
417
- agents: { http: config.httpAgent, https: config.httpsAgent },
502
+ agents: { http: httpAgent, https: httpsAgent },
418
503
  auth: auth,
419
504
  protocol: protocol,
420
505
  beforeRedirect: dispatchBeforeRedirect,
421
- beforeRedirects: {}
506
+ // Null-prototype. dispatchBeforeRedirect calls whatever it finds here, and
507
+ // the `config` hook is only populated when the caller supplies
508
+ // beforeRedirect, so a plain object left an inherited function reachable
509
+ // and able to rewrite the redirect target.
510
+ beforeRedirects: Object.create(null)
422
511
  };
423
512
 
424
513
  var socketPathError = checkSocketPath(config);
@@ -431,7 +520,6 @@ module.exports = function httpAdapter(config) {
431
520
  } else {
432
521
  options.hostname = parsed.hostname;
433
522
  options.port = parsed.port;
434
- var configProxy = utils.hasOwnProperty(config, 'proxy') ? config.proxy : undefined;
435
523
  setProxy(
436
524
  options,
437
525
  configProxy,
@@ -441,7 +529,14 @@ module.exports = function httpAdapter(config) {
441
529
 
442
530
  var transport;
443
531
  var isHttpsRequest = isHttps.test(options.protocol);
444
- options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
532
+ if (configProxy === false) {
533
+ setDirectAgent(options, httpAgent, httpsAgent);
534
+ options.beforeRedirects.direct = function(redirectOptions) {
535
+ setDirectAgent(redirectOptions, httpAgent, httpsAgent);
536
+ };
537
+ } else {
538
+ options.agent = isHttpsRequest ? httpsAgent : httpAgent;
539
+ }
445
540
  if (utils.hasOwnProperty(config, 'transport') && config.transport) {
446
541
  transport = config.transport;
447
542
  } else if (config.maxRedirects === 0) {
@@ -701,7 +796,7 @@ module.exports = function httpAdapter(config) {
701
796
  req.abort();
702
797
  reject(
703
798
  !cancel || cancel.type
704
- ? new CanceledError(null, config, req)
799
+ ? canceledErrorFromSignal(config.signal, config, req)
705
800
  : cancel
706
801
  );
707
802
  };
@@ -720,11 +815,9 @@ module.exports = function httpAdapter(config) {
720
815
  reject(AxiosError.from(err, config, null, req));
721
816
  });
722
817
 
723
- // follow-redirects enforces options.maxBodyLength for stream uploads, but the
724
- // native http/https transport (used when maxRedirects === 0) does not.
725
- // Count bytes ourselves so the limit is always honored.
726
- var nativeTransport = transport === http || transport === https;
727
- if (nativeTransport && config.maxBodyLength > -1) {
818
+ // Transform decodes string chunks to Buffers before counting, so every
819
+ // transport receives at most maxBodyLength encoded bytes.
820
+ if (config.maxBodyLength > -1) {
728
821
  var maxBodyLength = config.maxBodyLength;
729
822
  var uploadedBytes = 0;
730
823
  var bodyLimiter = new stream.Transform({
@@ -9,7 +9,7 @@ var parseHeaders = require('./../helpers/parseHeaders');
9
9
  var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
10
10
  var transitionalDefaults = require('../defaults/transitional');
11
11
  var AxiosError = require('../core/AxiosError');
12
- var CanceledError = require('../cancel/CanceledError');
12
+ var canceledErrorFromSignal = require('../cancel/fromSignal');
13
13
  var parseProtocol = require('../helpers/parseProtocol');
14
14
  var platform = require('../platform');
15
15
 
@@ -261,7 +261,7 @@ module.exports = function xhrAdapter(config) {
261
261
  }
262
262
  reject(
263
263
  !cancel || cancel.type
264
- ? new CanceledError(null, config, request)
264
+ ? canceledErrorFromSignal(config.signal, config, request)
265
265
  : cancel
266
266
  );
267
267
  request.abort();
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var CanceledError = require('./CanceledError');
4
+
5
+ module.exports = function fromSignal(signal, config, request) {
6
+ var error = new CanceledError(null, config, request);
7
+
8
+ if (signal) {
9
+ try {
10
+ var reason = signal.reason;
11
+ if (reason !== undefined) {
12
+ error.reason = reason;
13
+ }
14
+ } catch (e) {
15
+ // A custom signal getter must not prevent cancellation.
16
+ }
17
+ }
18
+
19
+ return error;
20
+ };
package/lib/core/Axios.js CHANGED
@@ -9,6 +9,56 @@ var buildFullPath = require('./buildFullPath');
9
9
  var validator = require('../helpers/validator');
10
10
 
11
11
  var validators = validator.validators;
12
+
13
+ function captureCallerStack(boundary) {
14
+ var caller = {};
15
+ try {
16
+ if (Error.captureStackTrace) {
17
+ Error.captureStackTrace(caller, boundary);
18
+ } else {
19
+ caller = new Error();
20
+ }
21
+ } catch (e) {
22
+ // Stack hooks must not prevent a request from being sent.
23
+ }
24
+ return caller;
25
+ }
26
+
27
+ function attachCallerStack(promise, caller) {
28
+ if (!caller) {
29
+ return promise;
30
+ }
31
+
32
+ return promise.then(null, function onRequestRejected(error) {
33
+ try {
34
+ if (error instanceof Error || Object.prototype.toString.call(error) === '[object Error]') {
35
+ // Capture at dispatch time, but only format the stack on failure.
36
+ // Capturing in this callback would lose callers using .then/.catch.
37
+ var stack = caller.stack;
38
+ if (typeof stack === 'string') {
39
+ var newline = stack.indexOf('\n');
40
+ stack = newline === -1 ? '' : stack.slice(newline + 1);
41
+ var original = error.stack;
42
+ if (stack && (original === undefined || original === null || original === '')) {
43
+ error.stack = stack;
44
+ } else if (stack && typeof original === 'string' && original.indexOf(stack) === -1) {
45
+ error.stack = original + '\n' + stack;
46
+ }
47
+ }
48
+ }
49
+ } catch (e) {
50
+ // Frozen errors and custom stack accessors must retain their rejection.
51
+ }
52
+ return Promise.reject(error);
53
+ });
54
+ }
55
+
56
+ function dispatchAfterRecovery(config) {
57
+ return function dispatchRecoveredRequest() {
58
+ return dispatchRequest(config);
59
+ };
60
+ }
61
+
12
62
  /**
13
63
  * Create a new instance of Axios
14
64
  *
@@ -38,12 +88,19 @@ Axios.prototype.request = function request(configOrUrl, config) {
38
88
  config = configOrUrl || {};
39
89
  }
40
90
 
41
- config = mergeConfig(this.defaults, config);
91
+ try {
92
+ config = mergeConfig(this.defaults, config);
93
+ } catch (error) {
94
+ return Promise.reject(error);
95
+ }
96
+ var caller = config.captureCallerStack === true ? captureCallerStack(request) : null;
42
97
 
43
- // Set config.method
98
+ // Set config.method. The merged config is null-prototype, but instance
99
+ // defaults may be an ordinary object, so the fallback is read as an own
100
+ // property to keep an inherited value from choosing the request method.
44
101
  if (config.method) {
45
102
  config.method = config.method.toLowerCase();
46
- } else if (this.defaults.method) {
103
+ } else if (utils.hasOwnProperty(this.defaults, 'method') && this.defaults.method) {
47
104
  config.method = this.defaults.method.toLowerCase();
48
105
  } else {
49
106
  config.method = 'get';
@@ -105,7 +162,7 @@ Axios.prototype.request = function request(configOrUrl, config) {
105
162
  promise = promise.then(chain.shift(), chain.shift());
106
163
  }
107
164
 
108
- return promise;
165
+ return attachCallerStack(promise, caller);
109
166
  }
110
167
 
111
168
 
@@ -114,24 +171,39 @@ Axios.prototype.request = function request(configOrUrl, config) {
114
171
  var onFulfilled = requestInterceptorChain.shift();
115
172
  var onRejected = requestInterceptorChain.shift();
116
173
  try {
117
- newConfig = onFulfilled(newConfig);
174
+ newConfig = onFulfilled ? onFulfilled(newConfig) : newConfig;
118
175
  } catch (error) {
119
- onRejected(error);
176
+ if (!onRejected) {
177
+ promise = Promise.reject(error);
178
+ break;
179
+ }
180
+ try {
181
+ var recovery = onRejected(error);
182
+ if (recovery && typeof recovery.then === 'function') {
183
+ promise = Promise.resolve(recovery).then(dispatchAfterRecovery(newConfig));
184
+ }
185
+ } catch (rejectedError) {
186
+ promise = Promise.reject(rejectedError);
187
+ }
120
188
  break;
121
189
  }
122
190
  }
123
191
 
124
- try {
125
- promise = dispatchRequest(newConfig);
126
- } catch (error) {
127
- return Promise.reject(error);
192
+ if (!promise) {
193
+ try {
194
+ promise = dispatchRequest(newConfig);
195
+ } catch (error) {
196
+ // Dispatch errors, including pre-aborted signals, still go through the
197
+ // response interceptors registered below.
198
+ promise = Promise.reject(error);
199
+ }
128
200
  }
129
201
 
130
202
  while (responseInterceptorChain.length) {
131
203
  promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
132
204
  }
133
205
 
134
- return promise;
206
+ return attachCallerStack(promise, caller);
135
207
  };
136
208
 
137
209
  Axios.prototype.getUri = function getUri(config) {
@@ -146,11 +218,16 @@ utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData
146
218
  Axios.prototype[method] = function(url, config) {
147
219
  var requestConfig = config || {};
148
220
 
149
- return this.request(mergeConfig(requestConfig, {
150
- method: method,
151
- url: url,
152
- data: utils.hasOwnProperty(requestConfig, 'data') ? requestConfig.data : undefined
153
- }));
221
+ try {
222
+ requestConfig = mergeConfig(requestConfig, {
223
+ method: method,
224
+ url: url,
225
+ data: utils.hasOwnProperty(requestConfig, 'data') ? requestConfig.data : undefined
226
+ });
227
+ } catch (error) {
228
+ return Promise.reject(error);
229
+ }
230
+ return this.request(requestConfig);
154
231
  };
155
232
  });
156
233
 
@@ -159,14 +236,20 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
159
236
 
160
237
  function generateHTTPMethod(isForm) {
161
238
  return function httpMethod(url, data, config) {
162
- return this.request(mergeConfig(config || {}, {
163
- method: method,
164
- headers: isForm ? {
165
- 'Content-Type': 'multipart/form-data'
166
- } : {},
167
- url: url,
168
- data: data
169
- }));
239
+ var requestConfig;
240
+ try {
241
+ requestConfig = mergeConfig(config || {}, {
242
+ method: method,
243
+ headers: isForm ? {
244
+ 'Content-Type': 'multipart/form-data'
245
+ } : {},
246
+ url: url,
247
+ data: data
248
+ });
249
+ } catch (error) {
250
+ return Promise.reject(error);
251
+ }
252
+ return this.request(requestConfig);
170
253
  };
171
254
  }
172
255
 
@@ -4,7 +4,7 @@ var utils = require('./../utils');
4
4
  var transformData = require('./transformData');
5
5
  var isCancel = require('../cancel/isCancel');
6
6
  var defaults = require('../defaults');
7
- var CanceledError = require('../cancel/CanceledError');
7
+ var canceledErrorFromSignal = require('../cancel/fromSignal');
8
8
  var normalizeHeaderName = require('../helpers/normalizeHeaderName');
9
9
  var sanitizeHeaderValue = require('../helpers/sanitizeHeaderValue');
10
10
 
@@ -17,7 +17,7 @@ function throwIfCancellationRequested(config) {
17
17
  }
18
18
 
19
19
  if (config.signal && config.signal.aborted) {
20
- throw new CanceledError();
20
+ throw canceledErrorFromSignal(config.signal, config);
21
21
  }
22
22
  }
23
23
 
@@ -30,8 +30,9 @@ function throwIfCancellationRequested(config) {
30
30
  module.exports = function dispatchRequest(config) {
31
31
  throwIfCancellationRequested(config);
32
32
 
33
- // Ensure headers exist
34
- config.headers = config.headers || {};
33
+ // Ensure headers exist. A request interceptor may return a replacement config
34
+ // that inherits from Object.prototype, so only an own headers value is used.
35
+ config.headers = (utils.hasOwnProperty(config, 'headers') && config.headers) || {};
35
36
 
36
37
  // Transform request data
37
38
  config.data = transformData.call(
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('../utils');
4
+ var assertParamsDepth = require('../helpers/assertParamsDepth');
4
5
 
5
6
  /**
6
7
  * Config-specific merge-function which creates a new config-object
@@ -13,6 +14,8 @@ var utils = require('../utils');
13
14
  module.exports = function mergeConfig(config1, config2) {
14
15
  // eslint-disable-next-line no-param-reassign
15
16
  config2 = config2 || {};
17
+ assertParamsDepth(utils.hasOwnProperty(config1, 'params') ? config1.params : undefined);
18
+ assertParamsDepth(utils.hasOwnProperty(config2, 'params') ? config2.params : undefined);
16
19
  // Use a null-prototype object so a polluted Object.prototype cannot leak
17
20
  // values (e.g. transport, adapter) into the returned config via inheritance.
18
21
  var config = Object.create(null);
@@ -63,6 +66,11 @@ module.exports = function mergeConfig(config1, config2) {
63
66
  }
64
67
  }
65
68
 
69
+ function defaultToConfig2Reference(prop) {
70
+ var value = getOwn(config2, prop);
71
+ return utils.isUndefined(value) ? getOwn(config1, prop) : value;
72
+ }
73
+
66
74
  // eslint-disable-next-line consistent-return
67
75
  function mergeDirectKeys(prop) {
68
76
  if (hasOwn(config2, prop)) {
@@ -98,6 +106,8 @@ module.exports = function mergeConfig(config1, config2) {
98
106
  'httpAgent': defaultToConfig2,
99
107
  'httpsAgent': defaultToConfig2,
100
108
  'cancelToken': defaultToConfig2,
109
+ // Signals are live objects; cloning them snapshots getters and reasons.
110
+ 'signal': defaultToConfig2Reference,
101
111
  'socketPath': defaultToConfig2,
102
112
  'allowedSocketPaths': defaultToConfig2,
103
113
  'responseEncoding': defaultToConfig2,
package/lib/env/data.js CHANGED
@@ -1,3 +1,3 @@
1
1
  module.exports = {
2
- "version": "0.33.0"
2
+ "version": "0.35.0"
3
3
  };
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../utils');
4
+ var AxiosError = require('../core/AxiosError');
5
+
6
+ // Match numeric array reads without scanning unoccupied slots or metadata.
7
+ function arrayIndexes(array) {
8
+ var length = array.length;
9
+ var indexes = Object.create(null);
10
+ var keys = [];
11
+ var source = array;
12
+ var fast = array;
13
+ while (source) {
14
+ var names = Object.getOwnPropertyNames(source);
15
+ for (var i = 0; i < names.length; i++) {
16
+ var key = names[i];
17
+ var index = +key;
18
+ if (index >= 0 && index < length && Math.floor(index) === index &&
19
+ String(index) === key && !indexes[key]) {
20
+ indexes[key] = true;
21
+ keys.push(key);
22
+ }
23
+ }
24
+ source = Object.getPrototypeOf(source);
25
+ // Detect unusual cyclic prototype chains with constant memory.
26
+ fast = fast && Object.getPrototypeOf(fast);
27
+ fast = fast && Object.getPrototypeOf(fast);
28
+ if (source && source === fast) {
29
+ throw new AxiosError('Circular prototype chain in params', AxiosError.ERR_BAD_OPTION_VALUE);
30
+ }
31
+ }
32
+ return keys.sort(function(a, b) { return a - b; });
33
+ }
34
+
35
+ module.exports = function assertParamsDepth(params) {
36
+ if (!utils.isObject(params)) return;
37
+ var pending = [{ value: params, depth: 0, complete: false }];
38
+ var ancestors = [];
39
+ var visited = null;
40
+ if (typeof WeakMap === 'function') {
41
+ visited = new WeakMap();
42
+ } else if (typeof Map === 'function') {
43
+ visited = new Map();
44
+ }
45
+ // Older runtimes can only compare immutable object identities by scanning.
46
+ // Keep that scan bounded; recently completed subgraphs avoid repeated work,
47
+ // while evicted shared subgraphs may be visited again.
48
+ var cacheSize = 128;
49
+ var visitedValues = [];
50
+ var visitedDepths = [];
51
+ var nextCacheIndex = 0;
52
+ while (pending.length) {
53
+ var entry = pending.pop();
54
+ var value = entry.value;
55
+ var index;
56
+ if (entry.complete) {
57
+ ancestors.pop();
58
+ if (visited) {
59
+ visited.set(value, entry.depth);
60
+ } else {
61
+ index = visitedValues.indexOf(value);
62
+ if (index === -1) {
63
+ index = nextCacheIndex;
64
+ nextCacheIndex = (nextCacheIndex + 1) % cacheSize;
65
+ }
66
+ visitedValues[index] = value;
67
+ visitedDepths[index] = entry.depth;
68
+ }
69
+ continue;
70
+ }
71
+ // The serializer enumerates any object at its root, then recursively
72
+ // visits only plain objects and arrays below that root.
73
+ if (entry.depth === 0 ? !utils.isObject(value) :
74
+ !utils.isPlainObject(value) && !utils.isArray(value)) {
75
+ continue;
76
+ }
77
+ if (entry.depth > 100) {
78
+ throw new AxiosError('params exceed the maximum depth of 100', AxiosError.ERR_BAD_OPTION_VALUE);
79
+ }
80
+ // The depth cap bounds this ancestry scan independently of params width.
81
+ if (ancestors.indexOf(value) !== -1) {
82
+ throw new AxiosError('Circular reference detected in params', AxiosError.ERR_BAD_OPTION_VALUE);
83
+ }
84
+ if (visited) {
85
+ if (visited.has(value) && visited.get(value) >= entry.depth) continue;
86
+ } else {
87
+ index = visitedValues.indexOf(value);
88
+ if (index !== -1 && visitedDepths[index] >= entry.depth) continue;
89
+ }
90
+ ancestors.push(value);
91
+ pending.push({ value: value, depth: entry.depth, complete: true });
92
+ var keys = utils.isArray(value) ? arrayIndexes(value) : Object.keys(value);
93
+ for (var i = 0; i < keys.length; i++) {
94
+ var key = keys[i];
95
+ if (key !== '__proto__' && key !== 'constructor' && key !== 'prototype') {
96
+ pending.push({ value: value[key], depth: entry.depth + 1, complete: false });
97
+ }
98
+ }
99
+ }
100
+ };
@@ -18,7 +18,8 @@ function estimateDataURLDecodedBytes(url) {
18
18
 
19
19
  var meta = url.slice(5, comma);
20
20
  var body = url.slice(comma + 1);
21
- var isBase64 = /;base64/i.test(meta);
21
+ // Match the exact encoding suffix accepted by fromDataURI.
22
+ var isBase64 = /(?:^|;)base64$/.test(meta);
22
23
 
23
24
  if (isBase64) {
24
25
  var effectiveLen = body.length;
@@ -68,8 +69,7 @@ function estimateDataURLDecodedBytes(url) {
68
69
  }
69
70
  }
70
71
 
71
- var groups = Math.floor(effectiveLen / 4);
72
- var bytes = groups * 3 - (pad || 0);
72
+ var bytes = Math.floor((effectiveLen - pad) * 3 / 4);
73
73
  return bytes > 0 ? bytes : 0;
74
74
  }
75
75