mirror of
https://github.com/tenrok/axios.git
synced 2026-05-30 15:24:11 +03:00
Release/0.21.4 (#4025)
* fix json transform when data is pre-stringified (#4020) * [Updating] incorrect JSON syntax in README.md * [Releasing] v0.21.4 Co-authored-by: Guillaume FORTAINE <guillaume+github@fortaine.com>
This commit is contained in:
@@ -1,5 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
### 0.21.4 (September 6, 2021)
|
||||
|
||||
Fixes and Functionality:
|
||||
- Fixing JSON transform when data is stringified. Providing backward compatability and complying to the JSON RFC standard ([#4020](https://github.com/axios/axios/pull/4020))
|
||||
|
||||
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
||||
|
||||
- [Jay](mailto:jasonsaayman@gmail.com)
|
||||
- [Guillaume Fortaine](https://github.com/gfortaine)
|
||||
- [Yusuke Kawasaki](https://github.com/kawanet)
|
||||
- [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
|
||||
|
||||
### 0.21.3 (September 4, 2021)
|
||||
|
||||
Fixes and Functionality:
|
||||
|
||||
@@ -474,7 +474,7 @@ These are the available config options for making requests. Only the `url` is re
|
||||
silentJSONParsing: true, // default value for the current Axios version
|
||||
|
||||
// try to parse the response string as JSON even if `responseType` is not 'json'
|
||||
forcedJSONParsing: true;
|
||||
forcedJSONParsing: true,
|
||||
|
||||
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
||||
clarifyTimeoutError: false,
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "axios",
|
||||
"main": "./dist/axios.js",
|
||||
"version": "0.21.3",
|
||||
"version": "0.21.4",
|
||||
"homepage": "https://axios-http.com",
|
||||
"authors": [
|
||||
"Matt Zabriskie"
|
||||
|
||||
Vendored
+18
-3
@@ -1,4 +1,4 @@
|
||||
/* axios v0.21.3 | (c) 2021 by Matt Zabriskie */
|
||||
/* axios v0.21.4 | (c) 2021 by Matt Zabriskie */
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory();
|
||||
@@ -1136,6 +1136,21 @@ function getDefaultAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
function stringifySafely(rawValue, parser, encoder) {
|
||||
if (utils.isString(rawValue)) {
|
||||
try {
|
||||
(parser || JSON.parse)(rawValue);
|
||||
return utils.trim(rawValue);
|
||||
} catch (e) {
|
||||
if (e.name !== 'SyntaxError') {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (encoder || JSON.stringify)(rawValue);
|
||||
}
|
||||
|
||||
var defaults = {
|
||||
|
||||
transitional: {
|
||||
@@ -1168,7 +1183,7 @@ var defaults = {
|
||||
}
|
||||
if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
|
||||
setContentTypeIfUnset(headers, 'application/json');
|
||||
return JSON.stringify(data);
|
||||
return stringifySafely(data);
|
||||
}
|
||||
return data;
|
||||
}],
|
||||
@@ -2169,7 +2184,7 @@ module.exports = {
|
||||
/*! exports provided: name, version, description, main, scripts, repository, keywords, author, license, bugs, homepage, devDependencies, browser, jsdelivr, unpkg, typings, dependencies, bundlesize, default */
|
||||
/***/ (function(module) {
|
||||
|
||||
module.exports = JSON.parse("{\"name\":\"axios\",\"version\":\"0.21.3\",\"description\":\"Promise based HTTP client for the browser and node.js\",\"main\":\"index.js\",\"scripts\":{\"test\":\"grunt test\",\"start\":\"node ./sandbox/server.js\",\"build\":\"NODE_ENV=production grunt build\",\"preversion\":\"npm test\",\"version\":\"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json\",\"postversion\":\"git push && git push --tags\",\"examples\":\"node ./examples/server.js\",\"coveralls\":\"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js\",\"fix\":\"eslint --fix lib/**/*.js\"},\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/axios/axios.git\"},\"keywords\":[\"xhr\",\"http\",\"ajax\",\"promise\",\"node\"],\"author\":\"Matt Zabriskie\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/axios/axios/issues\"},\"homepage\":\"https://axios-http.com\",\"devDependencies\":{\"coveralls\":\"^3.0.0\",\"es6-promise\":\"^4.2.4\",\"grunt\":\"^1.3.0\",\"grunt-banner\":\"^0.6.0\",\"grunt-cli\":\"^1.2.0\",\"grunt-contrib-clean\":\"^1.1.0\",\"grunt-contrib-watch\":\"^1.0.0\",\"grunt-eslint\":\"^23.0.0\",\"grunt-karma\":\"^4.0.0\",\"grunt-mocha-test\":\"^0.13.3\",\"grunt-ts\":\"^6.0.0-beta.19\",\"grunt-webpack\":\"^4.0.2\",\"istanbul-instrumenter-loader\":\"^1.0.0\",\"jasmine-core\":\"^2.4.1\",\"karma\":\"^6.3.2\",\"karma-chrome-launcher\":\"^3.1.0\",\"karma-firefox-launcher\":\"^2.1.0\",\"karma-jasmine\":\"^1.1.1\",\"karma-jasmine-ajax\":\"^0.1.13\",\"karma-safari-launcher\":\"^1.0.0\",\"karma-sauce-launcher\":\"^4.3.6\",\"karma-sinon\":\"^1.0.5\",\"karma-sourcemap-loader\":\"^0.3.8\",\"karma-webpack\":\"^4.0.2\",\"load-grunt-tasks\":\"^3.5.2\",\"minimist\":\"^1.2.0\",\"mocha\":\"^8.2.1\",\"sinon\":\"^4.5.0\",\"terser-webpack-plugin\":\"^4.2.3\",\"typescript\":\"^4.0.5\",\"url-search-params\":\"^0.10.0\",\"webpack\":\"^4.44.2\",\"webpack-dev-server\":\"^3.11.0\"},\"browser\":{\"./lib/adapters/http.js\":\"./lib/adapters/xhr.js\"},\"jsdelivr\":\"dist/axios.min.js\",\"unpkg\":\"dist/axios.min.js\",\"typings\":\"./index.d.ts\",\"dependencies\":{\"follow-redirects\":\"^1.14.0\"},\"bundlesize\":[{\"path\":\"./dist/axios.min.js\",\"threshold\":\"5kB\"}]}");
|
||||
module.exports = JSON.parse("{\"name\":\"axios\",\"version\":\"0.21.4\",\"description\":\"Promise based HTTP client for the browser and node.js\",\"main\":\"index.js\",\"scripts\":{\"test\":\"grunt test\",\"start\":\"node ./sandbox/server.js\",\"build\":\"NODE_ENV=production grunt build\",\"preversion\":\"npm test\",\"version\":\"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json\",\"postversion\":\"git push && git push --tags\",\"examples\":\"node ./examples/server.js\",\"coveralls\":\"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js\",\"fix\":\"eslint --fix lib/**/*.js\"},\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/axios/axios.git\"},\"keywords\":[\"xhr\",\"http\",\"ajax\",\"promise\",\"node\"],\"author\":\"Matt Zabriskie\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/axios/axios/issues\"},\"homepage\":\"https://axios-http.com\",\"devDependencies\":{\"coveralls\":\"^3.0.0\",\"es6-promise\":\"^4.2.4\",\"grunt\":\"^1.3.0\",\"grunt-banner\":\"^0.6.0\",\"grunt-cli\":\"^1.2.0\",\"grunt-contrib-clean\":\"^1.1.0\",\"grunt-contrib-watch\":\"^1.0.0\",\"grunt-eslint\":\"^23.0.0\",\"grunt-karma\":\"^4.0.0\",\"grunt-mocha-test\":\"^0.13.3\",\"grunt-ts\":\"^6.0.0-beta.19\",\"grunt-webpack\":\"^4.0.2\",\"istanbul-instrumenter-loader\":\"^1.0.0\",\"jasmine-core\":\"^2.4.1\",\"karma\":\"^6.3.2\",\"karma-chrome-launcher\":\"^3.1.0\",\"karma-firefox-launcher\":\"^2.1.0\",\"karma-jasmine\":\"^1.1.1\",\"karma-jasmine-ajax\":\"^0.1.13\",\"karma-safari-launcher\":\"^1.0.0\",\"karma-sauce-launcher\":\"^4.3.6\",\"karma-sinon\":\"^1.0.5\",\"karma-sourcemap-loader\":\"^0.3.8\",\"karma-webpack\":\"^4.0.2\",\"load-grunt-tasks\":\"^3.5.2\",\"minimist\":\"^1.2.0\",\"mocha\":\"^8.2.1\",\"sinon\":\"^4.5.0\",\"terser-webpack-plugin\":\"^4.2.3\",\"typescript\":\"^4.0.5\",\"url-search-params\":\"^0.10.0\",\"webpack\":\"^4.44.2\",\"webpack-dev-server\":\"^3.11.0\"},\"browser\":{\"./lib/adapters/http.js\":\"./lib/adapters/xhr.js\"},\"jsdelivr\":\"dist/axios.min.js\",\"unpkg\":\"dist/axios.min.js\",\"typings\":\"./index.d.ts\",\"dependencies\":{\"follow-redirects\":\"^1.14.0\"},\"bundlesize\":[{\"path\":\"./dist/axios.min.js\",\"threshold\":\"5kB\"}]}");
|
||||
|
||||
/***/ })
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+16
-1
@@ -26,6 +26,21 @@ function getDefaultAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
function stringifySafely(rawValue, parser, encoder) {
|
||||
if (utils.isString(rawValue)) {
|
||||
try {
|
||||
(parser || JSON.parse)(rawValue);
|
||||
return utils.trim(rawValue);
|
||||
} catch (e) {
|
||||
if (e.name !== 'SyntaxError') {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (encoder || JSON.stringify)(rawValue);
|
||||
}
|
||||
|
||||
var defaults = {
|
||||
|
||||
transitional: {
|
||||
@@ -58,7 +73,7 @@ var defaults = {
|
||||
}
|
||||
if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
|
||||
setContentTypeIfUnset(headers, 'application/json');
|
||||
return JSON.stringify(data);
|
||||
return stringifySafely(data);
|
||||
}
|
||||
return data;
|
||||
}],
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "axios",
|
||||
"version": "0.21.3",
|
||||
"version": "0.21.4",
|
||||
"description": "Promise based HTTP client for the browser and node.js",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
|
||||
@@ -20,6 +20,19 @@ describe('defaults', function () {
|
||||
expect(defaults.transformRequest[0]({foo: 'bar'})).toEqual('{"foo":"bar"}');
|
||||
});
|
||||
|
||||
it("should also transform request json when 'Content-Type' is 'application/json'", function () {
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
expect(defaults.transformRequest[0](JSON.stringify({ foo: 'bar' }), headers)).toEqual('{"foo":"bar"}');
|
||||
expect(defaults.transformRequest[0]([42, 43], headers)).toEqual('[42,43]');
|
||||
expect(defaults.transformRequest[0]('foo', headers)).toEqual('"foo"');
|
||||
expect(defaults.transformRequest[0](42, headers)).toEqual('42');
|
||||
expect(defaults.transformRequest[0](true, headers)).toEqual('true');
|
||||
expect(defaults.transformRequest[0](false, headers)).toEqual('false');
|
||||
expect(defaults.transformRequest[0](null, headers)).toEqual('null');
|
||||
});
|
||||
|
||||
it('should do nothing to request string', function () {
|
||||
expect(defaults.transformRequest[0]('foo=bar')).toEqual('foo=bar');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user