question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arrays in a request's config are merged positionally with the default config

See original GitHub issue

Hello 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
chinesedfancommented, Dec 20, 2019

@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. 😪

// axios/lib/utils.js, v0.18
function merge(/* obj1, obj2, obj3, ... */) {
  var result = {};
  function assignValue(val, key) {
    if (typeof result[key] === 'object' && typeof val === 'object') {
      result[key] = merge(result[key], val);
    } else {
      result[key] = val;
    }
  }

  for (var i = 0, l = arguments.length; i < l; i++) {
    forEach(arguments[i], assignValue);
  }
  return result;
}

//
merge([1,2],[3])
// {0: 3, 1: 2}
1reaction
chinesedfancommented, Dec 20, 2019

Duplicate of #2567. Sorry for the inconvenient.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoiding ASP.Net Core Configuration Pitfalls With Array Values
Configuration Solution #2. Include every position in the array, and make sure your primitive type is nullable. When you get your app setting, ......
Read more >
YAML Multi-Line Arrays - Stack Overflow
Short of creating multiple array mappings in YAML and merging them in my programming language of choice, is there any way to achieve...
Read more >
array_merge_recursive - Manual - PHP
array_merge_recursive() merges the elements of one or more arrays together so that the values of one are appended to the end of the...
Read more >
C H A P T E R 3 - Configuration Defaults and Guidelines
This section provides default configuration information for drives and channel settings. Default Logical Drive Configuration. Sun StorEdge 3000 family arrays ...
Read more >
Array manipulation - flatmap - KrakenD API Gateway
Avoid default usage of flatmap when not using arrays ... you will need an extra_config configuration inside your endpoint or backend section ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found