Arrays in a request's config are merged positionally with the default config
See original GitHub issueHello everyone,
first things first – thanks to all of you for devoting your valuable time to this project! I have not found a corresponding issue for this case and I am not sure whether it is a bug or a feature. If it is a feature, please read this post as a suggestion for a more explicit documentation of the behavior.
Describe the bug When I specify some request (or response) transformations in the default config and then use an empty array (or one with less transformation functions than the default has) in a request’s transformation config, some of the default transformations are still being applied.
To Reproduce
client = Axios.create({
transformRequest: [
deepKebabTransform,
JSON.stringify
]
})
// ...
// a)
client.put(url, data, { transformRequest: [] })
// b)
client.put(url, data, { transformRequest: [data => data] })
In both cases, JSON.stringify
is still run. In case a), both functions from the default config are applied.
Expected behavior
I would expect the default config entries for transformRequest
and transformResponse
(if not all array entries) to be either replaced completely by or merged with their counterparts in a request’s config.
Environment:
- Axios Version 0.18.0
- OS: OSX 10.15.2
- Browser: tested in Chrome 79.0.3945.88, Safari 13.0.4
Additional context
Regarding the merge
function in utils
I came to the assumption, that the arrays would likely be treated as objects and thus their entries are effectively overridden positionally.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
@lagr Oops, I noticed that you are using 0.18. The old codes have similar bug.
Maybe you can try 0.19, but be careful with other new changes/bugs. 😪
Duplicate of #2567. Sorry for the inconvenient.