mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
Fix: Don't add null values to query string. (#5108)
* feat: add boolean flag to mimic pre 1.x behavior for paramsSerializer custom function * chore: update ParamsSerializer Readme * fix: dont slice hash off URL if not appending params * Omit nulls from formData serialization * fix: dont add nulls or undefined values to arrays either * readme update * fix test * chore: documentation * chore: do TS properly Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
committed by
GitHub
parent
ef1c48a476
commit
b0ebf9fcac
@@ -35,13 +35,7 @@ export default function buildURL(url, params, options) {
|
||||
if (!params) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const hashmarkIndex = url.indexOf('#');
|
||||
|
||||
if (hashmarkIndex !== -1) {
|
||||
url = url.slice(0, hashmarkIndex);
|
||||
}
|
||||
|
||||
|
||||
const _encode = options && options.encode || encode;
|
||||
|
||||
const serializeFn = options && options.serialize;
|
||||
@@ -57,6 +51,11 @@ export default function buildURL(url, params, options) {
|
||||
}
|
||||
|
||||
if (serializedParams) {
|
||||
const hashmarkIndex = url.indexOf("#");
|
||||
|
||||
if (hashmarkIndex !== -1) {
|
||||
url = url.slice(0, hashmarkIndex);
|
||||
}
|
||||
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ function toFormData(obj, formData, options) {
|
||||
key = removeBrackets(key);
|
||||
|
||||
arr.forEach(function each(el, index) {
|
||||
!utils.isUndefined(el) && formData.append(
|
||||
!(utils.isUndefined(el) || el === null) && formData.append(
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
|
||||
convertValue(el)
|
||||
@@ -205,7 +205,7 @@ function toFormData(obj, formData, options) {
|
||||
stack.push(value);
|
||||
|
||||
utils.forEach(value, function each(el, key) {
|
||||
const result = !utils.isUndefined(el) && visitor.call(
|
||||
const result = !(utils.isUndefined(el) || el === null) && visitor.call(
|
||||
formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user