axios 0.32.0 → 0.33.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.
@@ -373,9 +373,10 @@ module.exports = function httpAdapter(config) {
373
373
 
374
374
  // HTTP basic authentication
375
375
  var auth = undefined;
376
- if (config.auth) {
377
- var username = config.auth.username || '';
378
- var password = config.auth.password || '';
376
+ var configAuth = utils.hasOwnProperty(config, 'auth') ? config.auth : undefined;
377
+ if (configAuth) {
378
+ var username = utils.hasOwnProperty(configAuth, 'username') ? configAuth.username || '' : '';
379
+ var password = utils.hasOwnProperty(configAuth, 'password') ? configAuth.password || '' : '';
379
380
  auth = username + ':' + password;
380
381
  }
381
382
 
@@ -390,8 +391,10 @@ module.exports = function httpAdapter(config) {
390
391
  delete headers[headerNames.authorization];
391
392
  }
392
393
 
394
+ var paramsSerializer = utils.hasOwnProperty(config, 'paramsSerializer') ? config.paramsSerializer : undefined;
395
+
393
396
  try {
394
- buildURL(parsed.path, config.params, config.paramsSerializer).replace(
397
+ buildURL(parsed.path, config.params, paramsSerializer).replace(
395
398
  /^\?/,
396
399
  ''
397
400
  );
@@ -407,7 +410,7 @@ module.exports = function httpAdapter(config) {
407
410
  path: buildURL(
408
411
  parsed.path,
409
412
  config.params,
410
- config.paramsSerializer
413
+ paramsSerializer
411
414
  ).replace(/^\?/, ''),
412
415
  method: method,
413
416
  headers: headers,
@@ -428,9 +431,10 @@ module.exports = function httpAdapter(config) {
428
431
  } else {
429
432
  options.hostname = parsed.hostname;
430
433
  options.port = parsed.port;
434
+ var configProxy = utils.hasOwnProperty(config, 'proxy') ? config.proxy : undefined;
431
435
  setProxy(
432
436
  options,
433
- config.proxy,
437
+ configProxy,
434
438
  protocol + '//' + parsed.host + options.path
435
439
  );
436
440
  }
@@ -40,10 +40,11 @@ module.exports = function xhrAdapter(config) {
40
40
  var request = new XMLHttpRequest();
41
41
 
42
42
  // HTTP basic authentication
43
- if (config.auth) {
44
- var username = config.auth.username || '';
45
- var password = config.auth.password
46
- ? unescape(encodeURIComponent(config.auth.password))
43
+ var configAuth = utils.hasOwnProperty(config, 'auth') ? config.auth : undefined;
44
+ if (configAuth) {
45
+ var username = utils.hasOwnProperty(configAuth, 'username') ? configAuth.username || '' : '';
46
+ var password = utils.hasOwnProperty(configAuth, 'password') && configAuth.password
47
+ ? unescape(encodeURIComponent(configAuth.password))
47
48
  : '';
48
49
  requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
49
50
  }
@@ -56,7 +57,11 @@ module.exports = function xhrAdapter(config) {
56
57
 
57
58
  request.open(
58
59
  config.method.toUpperCase(),
59
- buildURL(fullPath, config.params, config.paramsSerializer),
60
+ buildURL(
61
+ fullPath,
62
+ config.params,
63
+ utils.hasOwnProperty(config, 'paramsSerializer') ? config.paramsSerializer : undefined
64
+ ),
60
65
  true
61
66
  );
62
67
 
package/lib/core/Axios.js CHANGED
@@ -144,10 +144,12 @@ Axios.prototype.getUri = function getUri(config) {
144
144
  utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
145
145
  /*eslint func-names:0*/
146
146
  Axios.prototype[method] = function(url, config) {
147
- return this.request(mergeConfig(config || {}, {
147
+ var requestConfig = config || {};
148
+
149
+ return this.request(mergeConfig(requestConfig, {
148
150
  method: method,
149
151
  url: url,
150
- data: (config || {}).data
152
+ data: utils.hasOwnProperty(requestConfig, 'data') ? requestConfig.data : undefined
151
153
  }));
152
154
  };
153
155
  });
package/lib/env/data.js CHANGED
@@ -1,3 +1,3 @@
1
1
  module.exports = {
2
- "version": "0.32.0"
2
+ "version": "0.33.0"
3
3
  };
@@ -33,9 +33,17 @@ module.exports = function buildURL(url, params, options) {
33
33
  url = url.slice(0, hashmarkIndex);
34
34
  }
35
35
 
36
- var _encode = options && options.encode || encode;
37
-
38
- var serializeFn = options && options.serialize;
36
+ var _encode = encode;
37
+ var serializeFn;
38
+
39
+ if (options) {
40
+ if (utils.isFunction(options)) {
41
+ serializeFn = options;
42
+ } else {
43
+ _encode = utils.hasOwnProperty(options, 'encode') && options.encode || encode;
44
+ serializeFn = utils.hasOwnProperty(options, 'serialize') ? options.serialize : undefined;
45
+ }
46
+ }
39
47
 
40
48
  var serializedParams;
41
49
 
@@ -1,6 +1,20 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('../utils');
4
+ var AxiosError = require('../core/AxiosError');
5
+
6
+ var MAX_FORM_DATA_TO_JSON_DEPTH = 100;
7
+
8
+ function assertPathDepth(path) {
9
+ var depth = path.length - 1;
10
+
11
+ if (depth > MAX_FORM_DATA_TO_JSON_DEPTH) {
12
+ throw new AxiosError(
13
+ 'Maximum object depth of ' + MAX_FORM_DATA_TO_JSON_DEPTH + ' exceeded (got ' + depth + ' levels)',
14
+ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
15
+ );
16
+ }
17
+ }
4
18
 
5
19
  function parsePropPath(name) {
6
20
  // foo[x][y][z]
@@ -62,7 +76,10 @@ function formDataToJSON(formData) {
62
76
  var obj = {};
63
77
 
64
78
  utils.forEachEntry(formData, function(name, value) {
65
- buildPath(parsePropPath(name), value, obj, 0);
79
+ var path = parsePropPath(name);
80
+
81
+ assertPathDepth(path);
82
+ buildPath(path, value, obj, 0);
66
83
  });
67
84
 
68
85
  return obj;
@@ -123,7 +123,7 @@ function isLoopbackIPv4(hostname) {
123
123
  }
124
124
 
125
125
  function isLoopbackHost(hostname) {
126
- return hostname === 'localhost' || hostname === '::1' || isLoopbackIPv4(hostname);
126
+ return hostname === 'localhost' || hostname === '::1' || hostname === '0.0.0.0' || isLoopbackIPv4(hostname);
127
127
  }
128
128
 
129
129
  module.exports = function shouldBypassProxy(location) {
@@ -94,6 +94,29 @@ function toFormData(obj, formData, options) {
94
94
  return value;
95
95
  }
96
96
 
97
+ var stack = [];
98
+
99
+ function assertValueDepth(value, depth) {
100
+ if (depth > maxDepth) {
101
+ throw new AxiosError(
102
+ 'Maximum object depth of ' + maxDepth + ' exceeded (got ' + depth + ' levels)',
103
+ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
104
+ );
105
+ }
106
+
107
+ if (!utils.isObject(value) || stack.indexOf(value) !== -1) {
108
+ return;
109
+ }
110
+
111
+ stack.push(value);
112
+
113
+ utils.forEach(value, function each(el) {
114
+ assertValueDepth(el, depth + 1);
115
+ });
116
+
117
+ stack.pop();
118
+ }
119
+
97
120
  /**
98
121
  *
99
122
  * @param {*} value
@@ -109,6 +132,7 @@ function toFormData(obj, formData, options) {
109
132
  if (utils.endsWith(key, '{}')) {
110
133
  // eslint-disable-next-line no-param-reassign
111
134
  key = metaTokens ? key : key.slice(0, -2);
135
+ assertValueDepth(value, 1);
112
136
  // eslint-disable-next-line no-param-reassign
113
137
  value = JSON.stringify(value);
114
138
  } else if (
@@ -138,8 +162,6 @@ function toFormData(obj, formData, options) {
138
162
  return false;
139
163
  }
140
164
 
141
- var stack = [];
142
-
143
165
  var exposedHelpers = Object.assign(predicates, {
144
166
  defaultVisitor: defaultVisitor,
145
167
  convertValue: convertValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",