axios 0.34.0 → 0.36.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/dist/esm/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // axios v0.34.0 Copyright (c) 2026 Matt Zabriskie
1
+ // axios v0.36.0 Copyright (c) 2026 Matt Zabriskie
2
2
  var bind = function bind(fn, thisArg) {
3
3
  return function wrap() {
4
4
  return fn.apply(thisArg, arguments);
@@ -511,10 +511,75 @@ function toArray(thing) {
511
511
  if (!thing) return null;
512
512
  if (isArray(thing)) return thing;
513
513
  var i = thing.length;
514
- if (!isNumber(i)) return null;
514
+ if (typeof i !== 'number' || i < 0 || i > 0xffffffff || Math.floor(i) !== i) return null;
515
+
516
+ // Legacy FileList hosts expose indexed reads without reflecting their keys.
517
+ if (isFileList(thing)) {
518
+ var files = [];
519
+ while (i-- > 0) {
520
+ var file = thing[i];
521
+ if (file === null || isUndefined(file)) return null;
522
+ defineOwnProperty(files, i, file);
523
+ }
524
+ return files;
525
+ }
526
+
527
+ // Count actual indexes, including hidden collection properties, before
528
+ // allocating from the declared length. Box primitives for ES5 object APIs.
529
+ var source = Object(thing);
530
+ var indexes = Object.create(null);
531
+ var count = 0;
532
+ var seen = [];
533
+ var owns = Object.prototype.hasOwnProperty;
534
+
535
+ while (source && count < i) {
536
+ if (seen.indexOf(source) !== -1) return null;
537
+ defineOwnProperty(seen, seen.length, source);
538
+
539
+ if (source === Object.prototype) break;
540
+
541
+ var prototype = Object.getPrototypeOf(source);
542
+ if (prototype === null) {
543
+ var constructorDescriptor = Object.getOwnPropertyDescriptor(source, 'constructor');
544
+ var constructorValue = constructorDescriptor && owns.call(constructorDescriptor, 'value') &&
545
+ constructorDescriptor.value;
546
+ var constructorPrototype = typeof constructorValue === 'function' &&
547
+ Object.getOwnPropertyDescriptor(constructorValue, 'prototype');
548
+
549
+ // Recognize another realm's Object.prototype without excluding
550
+ // application-defined null-prototype parents or invoking accessors.
551
+ if (
552
+ constructorPrototype && owns.call(constructorPrototype, 'value') &&
553
+ constructorPrototype.value === source &&
554
+ Function.prototype.toString.call(constructorValue) === Function.prototype.toString.call(Object)
555
+ ) {
556
+ break;
557
+ }
558
+ }
559
+
560
+ var keys = Object.getOwnPropertyNames(source);
561
+ for (var j = 0; j < keys.length; j++) {
562
+ var key = keys[j];
563
+ var index = +key;
564
+ if (
565
+ index >= 0 &&
566
+ index < i &&
567
+ Math.floor(index) === index &&
568
+ String(index) === key &&
569
+ owns.call(source, key) &&
570
+ !indexes[key]
571
+ ) {
572
+ indexes[key] = true;
573
+ count++;
574
+ }
575
+ }
576
+ source = prototype;
577
+ }
578
+
579
+ if (count !== i) return null;
515
580
  var arr = new Array(i);
516
581
  while (i-- > 0) {
517
- arr[i] = thing[i];
582
+ defineOwnProperty(arr, i, thing[i]);
518
583
  }
519
584
  return arr;
520
585
  }
@@ -584,6 +649,7 @@ var utils = {
584
649
  trim: trim,
585
650
  stripBOM: stripBOM,
586
651
  inherits: inherits,
652
+ defineOwnProperty: defineOwnProperty,
587
653
  toFlatObject: toFlatObject,
588
654
  kindOf: kindOf,
589
655
  kindOfTest: kindOfTest,
@@ -905,7 +971,7 @@ function toFormData(obj, formData, options) {
905
971
  return;
906
972
  }
907
973
 
908
- stack.push(value);
974
+ utils.defineOwnProperty(stack, stack.length, value);
909
975
 
910
976
  utils.forEach(value, function each(el) {
911
977
  assertValueDepth(el, depth + 1);
@@ -934,8 +1000,8 @@ function toFormData(obj, formData, options) {
934
1000
  value = JSON.stringify(value);
935
1001
  } else if (
936
1002
  (utils.isArray(value) && isFlatArray(value)) ||
937
- (utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
938
- )) {
1003
+ ((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value)))
1004
+ ) {
939
1005
  // eslint-disable-next-line no-param-reassign
940
1006
  key = removeBrackets(key);
941
1007
 
@@ -982,7 +1048,7 @@ function toFormData(obj, formData, options) {
982
1048
  throw Error('Circular reference detected in ' + path.join('.'));
983
1049
  }
984
1050
 
985
- stack.push(value);
1051
+ utils.defineOwnProperty(stack, stack.length, value);
986
1052
 
987
1053
  utils.forEach(value, function each(el, key) {
988
1054
  var result = !(utils.isUndefined(el) || el === null) && visitor.call(
@@ -1130,8 +1196,8 @@ InterceptorManager.prototype.use = function use(fulfilled, rejected, options) {
1130
1196
  this.handlers.push({
1131
1197
  fulfilled: fulfilled,
1132
1198
  rejected: rejected,
1133
- synchronous: options ? options.synchronous : false,
1134
- runWhen: options ? options.runWhen : null
1199
+ synchronous: options && utils.hasOwnProperty(options, 'synchronous') ? options.synchronous : false,
1200
+ runWhen: options && utils.hasOwnProperty(options, 'runWhen') ? options.runWhen : null
1135
1201
  });
1136
1202
  return this.handlers.length - 1;
1137
1203
  };
@@ -1254,13 +1320,50 @@ function arrayToObject(arr) {
1254
1320
  return obj;
1255
1321
  }
1256
1322
 
1323
+ function normalizeArray(value) {
1324
+ if (!utils.isArray(value)) return value;
1325
+
1326
+ var keys = Object.keys(value);
1327
+ if (keys.length !== value.length) return arrayToObject(value);
1328
+
1329
+ for (var i = 0; i < keys.length; i++) {
1330
+ var index = +keys[i];
1331
+ if (
1332
+ index < 0 || index >= value.length ||
1333
+ Math.floor(index) !== index || String(index) !== keys[i]
1334
+ ) {
1335
+ return arrayToObject(value);
1336
+ }
1337
+ }
1338
+
1339
+ return value;
1340
+ }
1341
+
1342
+ function normalizeArrays(obj) {
1343
+ var pending = [obj];
1344
+ function normalizeEntry(target, key) {
1345
+ var value = target[key] = normalizeArray(target[key]);
1346
+ if (utils.isArray(value) || utils.isPlainObject(value)) {
1347
+ pending.push(value);
1348
+ }
1349
+ }
1350
+ while (pending.length) {
1351
+ var target = pending.pop();
1352
+ var keys = Object.keys(target);
1353
+ for (var i = 0; i < keys.length; i++) {
1354
+ normalizeEntry(target, keys[i]);
1355
+ }
1356
+ }
1357
+ return obj;
1358
+ }
1359
+
1257
1360
  function formDataToJSON(formData) {
1258
1361
  function buildPath(path, value, target, index) {
1259
1362
  var name = path[index++];
1260
1363
 
1261
1364
  if (name === '__proto__') return true;
1262
1365
 
1263
- var isNumericKey = Number.isFinite(+name);
1366
+ var isNumericKey = isFinite(+name);
1264
1367
  var isLast = index >= path.length;
1265
1368
  name = !name && utils.isArray(target) ? target.length : name;
1266
1369
 
@@ -1274,7 +1377,7 @@ function formDataToJSON(formData) {
1274
1377
  return !isNumericKey;
1275
1378
  }
1276
1379
 
1277
- if (!target[name] || !utils.isObject(target[name])) {
1380
+ if (!utils.hasOwnProperty(target, name) || !utils.isObject(target[name])) {
1278
1381
  target[name] = [];
1279
1382
  }
1280
1383
 
@@ -1297,7 +1400,7 @@ function formDataToJSON(formData) {
1297
1400
  buildPath(path, value, obj, 0);
1298
1401
  });
1299
1402
 
1300
- return obj;
1403
+ return normalizeArrays(obj);
1301
1404
  }
1302
1405
 
1303
1406
  return null;
@@ -1411,9 +1514,21 @@ var isAbsoluteURL = function isAbsoluteURL(url) {
1411
1514
  * @returns {string} The combined URL
1412
1515
  */
1413
1516
  var combineURLs = function combineURLs(baseURL, relativeURL) {
1414
- return relativeURL
1415
- ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1416
- : baseURL;
1517
+ if (!relativeURL) {
1518
+ return baseURL;
1519
+ }
1520
+
1521
+ var base = baseURL.replace(/\/?\/$/, '');
1522
+
1523
+ if (/^\/*$/.test(base)) {
1524
+ // A base made only of slashes points at the root of the current origin.
1525
+ // Drop leading slashes, backslashes, tabs and newlines from the relative
1526
+ // URL as well: URL parsers ignore tabs and newlines and treat '\' as '/',
1527
+ // so leaving them would turn the result into a protocol-relative URL.
1528
+ return '/' + relativeURL.replace(/^[\/\\\t\n\r]+/, '');
1529
+ }
1530
+
1531
+ return base + '/' + relativeURL.replace(/^\/+/, '');
1417
1532
  };
1418
1533
 
1419
1534
  /**
@@ -2191,6 +2306,102 @@ var dispatchRequest = function dispatchRequest(config) {
2191
2306
  });
2192
2307
  };
2193
2308
 
2309
+ // Match numeric array reads without scanning unoccupied slots or metadata.
2310
+ function arrayIndexes(array) {
2311
+ var length = array.length;
2312
+ var indexes = Object.create(null);
2313
+ var keys = [];
2314
+ var source = array;
2315
+ var fast = array;
2316
+ while (source) {
2317
+ var names = Object.getOwnPropertyNames(source);
2318
+ for (var i = 0; i < names.length; i++) {
2319
+ var key = names[i];
2320
+ var index = +key;
2321
+ if (index >= 0 && index < length && Math.floor(index) === index &&
2322
+ String(index) === key && !indexes[key]) {
2323
+ indexes[key] = true;
2324
+ keys.push(key);
2325
+ }
2326
+ }
2327
+ source = Object.getPrototypeOf(source);
2328
+ // Detect unusual cyclic prototype chains with constant memory.
2329
+ fast = fast && Object.getPrototypeOf(fast);
2330
+ fast = fast && Object.getPrototypeOf(fast);
2331
+ if (source && source === fast) {
2332
+ throw new AxiosError_1('Circular prototype chain in params', AxiosError_1.ERR_BAD_OPTION_VALUE);
2333
+ }
2334
+ }
2335
+ return keys.sort(function(a, b) { return a - b; });
2336
+ }
2337
+
2338
+ var assertParamsDepth = function assertParamsDepth(params) {
2339
+ if (!utils.isObject(params)) return;
2340
+ var pending = [{ value: params, depth: 0, complete: false }];
2341
+ var ancestors = [];
2342
+ var visited = null;
2343
+ if (typeof WeakMap === 'function') {
2344
+ visited = new WeakMap();
2345
+ } else if (typeof Map === 'function') {
2346
+ visited = new Map();
2347
+ }
2348
+ // Older runtimes can only compare immutable object identities by scanning.
2349
+ // Keep that scan bounded; recently completed subgraphs avoid repeated work,
2350
+ // while evicted shared subgraphs may be visited again.
2351
+ var cacheSize = 128;
2352
+ var visitedValues = [];
2353
+ var visitedDepths = [];
2354
+ var nextCacheIndex = 0;
2355
+ while (pending.length) {
2356
+ var entry = pending.pop();
2357
+ var value = entry.value;
2358
+ var index;
2359
+ if (entry.complete) {
2360
+ ancestors.pop();
2361
+ if (visited) {
2362
+ visited.set(value, entry.depth);
2363
+ } else {
2364
+ index = visitedValues.indexOf(value);
2365
+ if (index === -1) {
2366
+ index = nextCacheIndex;
2367
+ nextCacheIndex = (nextCacheIndex + 1) % cacheSize;
2368
+ }
2369
+ visitedValues[index] = value;
2370
+ visitedDepths[index] = entry.depth;
2371
+ }
2372
+ continue;
2373
+ }
2374
+ // The serializer enumerates any object at its root, then recursively
2375
+ // visits only plain objects and arrays below that root.
2376
+ if (entry.depth === 0 ? !utils.isObject(value) :
2377
+ !utils.isPlainObject(value) && !utils.isArray(value)) {
2378
+ continue;
2379
+ }
2380
+ if (entry.depth > 100) {
2381
+ throw new AxiosError_1('params exceed the maximum depth of 100', AxiosError_1.ERR_BAD_OPTION_VALUE);
2382
+ }
2383
+ // The depth cap bounds this ancestry scan independently of params width.
2384
+ if (ancestors.indexOf(value) !== -1) {
2385
+ throw new AxiosError_1('Circular reference detected in params', AxiosError_1.ERR_BAD_OPTION_VALUE);
2386
+ }
2387
+ if (visited) {
2388
+ if (visited.has(value) && visited.get(value) >= entry.depth) continue;
2389
+ } else {
2390
+ index = visitedValues.indexOf(value);
2391
+ if (index !== -1 && visitedDepths[index] >= entry.depth) continue;
2392
+ }
2393
+ ancestors.push(value);
2394
+ pending.push({ value: value, depth: entry.depth, complete: true });
2395
+ var keys = utils.isArray(value) ? arrayIndexes(value) : Object.keys(value);
2396
+ for (var i = 0; i < keys.length; i++) {
2397
+ var key = keys[i];
2398
+ if (key !== '__proto__' && key !== 'constructor' && key !== 'prototype') {
2399
+ pending.push({ value: value[key], depth: entry.depth + 1, complete: false });
2400
+ }
2401
+ }
2402
+ }
2403
+ };
2404
+
2194
2405
  /**
2195
2406
  * Config-specific merge-function which creates a new config-object
2196
2407
  * by merging two configuration objects together.
@@ -2202,6 +2413,8 @@ var dispatchRequest = function dispatchRequest(config) {
2202
2413
  var mergeConfig = function mergeConfig(config1, config2) {
2203
2414
  // eslint-disable-next-line no-param-reassign
2204
2415
  config2 = config2 || {};
2416
+ assertParamsDepth(utils.hasOwnProperty(config1, 'params') ? config1.params : undefined);
2417
+ assertParamsDepth(utils.hasOwnProperty(config2, 'params') ? config2.params : undefined);
2205
2418
  // Use a null-prototype object so a polluted Object.prototype cannot leak
2206
2419
  // values (e.g. transport, adapter) into the returned config via inheritance.
2207
2420
  var config = Object.create(null);
@@ -2313,7 +2526,7 @@ var mergeConfig = function mergeConfig(config1, config2) {
2313
2526
  };
2314
2527
 
2315
2528
  var data = {
2316
- "version": "0.34.0"
2529
+ "version": "0.36.0"
2317
2530
  };
2318
2531
 
2319
2532
  var VERSION = data.version;
@@ -2481,7 +2694,11 @@ Axios.prototype.request = function request(configOrUrl, config) {
2481
2694
  config = configOrUrl || {};
2482
2695
  }
2483
2696
 
2484
- config = mergeConfig(this.defaults, config);
2697
+ try {
2698
+ config = mergeConfig(this.defaults, config);
2699
+ } catch (error) {
2700
+ return Promise.reject(error);
2701
+ }
2485
2702
  var caller = config.captureCallerStack === true ? captureCallerStack(request) : null;
2486
2703
 
2487
2704
  // Set config.method. The merged config is null-prototype, but instance
@@ -2607,11 +2824,16 @@ utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData
2607
2824
  Axios.prototype[method] = function(url, config) {
2608
2825
  var requestConfig = config || {};
2609
2826
 
2610
- return this.request(mergeConfig(requestConfig, {
2611
- method: method,
2612
- url: url,
2613
- data: utils.hasOwnProperty(requestConfig, 'data') ? requestConfig.data : undefined
2614
- }));
2827
+ try {
2828
+ requestConfig = mergeConfig(requestConfig, {
2829
+ method: method,
2830
+ url: url,
2831
+ data: utils.hasOwnProperty(requestConfig, 'data') ? requestConfig.data : undefined
2832
+ });
2833
+ } catch (error) {
2834
+ return Promise.reject(error);
2835
+ }
2836
+ return this.request(requestConfig);
2615
2837
  };
2616
2838
  });
2617
2839
 
@@ -2620,14 +2842,20 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
2620
2842
 
2621
2843
  function generateHTTPMethod(isForm) {
2622
2844
  return function httpMethod(url, data, config) {
2623
- return this.request(mergeConfig(config || {}, {
2624
- method: method,
2625
- headers: isForm ? {
2626
- 'Content-Type': 'multipart/form-data'
2627
- } : {},
2628
- url: url,
2629
- data: data
2630
- }));
2845
+ var requestConfig;
2846
+ try {
2847
+ requestConfig = mergeConfig(config || {}, {
2848
+ method: method,
2849
+ headers: isForm ? {
2850
+ 'Content-Type': 'multipart/form-data'
2851
+ } : {},
2852
+ url: url,
2853
+ data: data
2854
+ });
2855
+ } catch (error) {
2856
+ return Promise.reject(error);
2857
+ }
2858
+ return this.request(requestConfig);
2631
2859
  };
2632
2860
  }
2633
2861