fix: preserve symbol keys in merged request data#10812
Conversation
jasonsaayman
left a comment
There was a problem hiding this comment.
Thanks for the patch @LaplaceYoung. A couple of things to address before this can go in.
1. Avoid the per-request hot path allocation in lib/utils.js.
utils.merge runs on every request through mergeConfig, Axios.js:148, and lib/adapters/fetch.js:37. The new code allocates two arrays per source object (the getOwnPropertySymbols result and the .filter result) even when there are zero symbol keys, which is the common case for almost every config merge. Can you switch to a length-guarded indexed loop:
const symbols = Object.getOwnPropertySymbols(source);
for (let j = 0; j < symbols.length; j++) {
const sym = symbols[j];
if (Object.prototype.propertyIsEnumerable.call(source, sym)) {
assignValue(source[sym], sym);
}
}That keeps the behavior but skips the .filter array entirely, and the loop body is dead when there are no symbols.
2. Drop the unrelated formatting changes.
The Prettier touch-ups in lib/utils.js:192-209 and 264-271 (semicolons on the arrow IIFEs, JSDoc whitespace, parens around the isFormData return) are not part of the fix. Please pull them out into a separate style: or chore: commit, or just revert them from this PR. Drive-by reformatting on a maintenance-line file makes git blame noisy and breaks the "failing test plus fix in separate commits" hygiene the PR template asks for.
Non-blocking nits, take or leave:
- A test that confirms non-enumerable symbols are skipped would lock in the
propertyIsEnumerablefilter. Right now it is untested. - A caseless test mixing string and symbol keys (via
merge.call({ caseless: true }, ...)) would also be nice to have, to pin the newtypeof key === 'string'guard at line 413. - In the PR body, the three vitest failures you listed (postman-echo timeout, DNS timeout,
UND_ERR_SOCKET) are pre-existing flakes. Worth saying so explicitly so the next reviewer does not re-investigate.
Let me know when the PR has been updated and I will take a look again
|
Hi, Severity: informational | Category: correctness How to fix: Skip symbols for Buffers Agent prompt to fix - you can give this to your LLM of choice:
Found by Qodo code review |
|
Thanks a lot for checking and reviewing my PR. I'm currently on the May Day holiday and didn't bring my work laptop with me, so I can't make timely edits to the PR right now. |
|
Updated this PR for the review feedback:
Verification run:
@jasonsaayman ready for another look. |
|
Updated again to resolve the GitHub conflict without merging the latest What changed:
Verification run:
|
…ipUndefined semantics
…s.create covering the instance
|
Woo! Thanks, guys. |
* fix: preserve symbol keys in merged request data * fix: address symbol merge review feedback * fix: align symbol merge with v1.x own-prop guard * fix: avoid merge conflict on target key handling * feat: collapsed the duplicated typeof key === symbol branch in assignValue * chore: added should honor skipUndefined for symbol keys to lock in skipUndefined semantics * chore: added should pass symbol keys to transformRequest through axios.create covering the instance * fix(utils): skip symbol scan for arrays --------- Co-authored-by: laplace young <[email protected]> Co-authored-by: Jay <[email protected]>
Summary
utils.merge.forEachbehavior.transformRequest.Verification
npx vitest run --project unit tests/unit/utils/merge.test.js tests/unit/api.test.jsnpx eslint lib/utils.jsnpx prettier --check tests/unit/utils/merge.test.js tests/unit/api.test.jsgit diff origin/v1.x...HEAD --checkThe final PR diff leaves the existing
lib/utils.jsformatting unchanged relative tov1.x.npm run test:vitest:unitreached 583 passing tests out of 586. The three failures were existing network/DNS-dependent cases:postman-echo.comtimeout, invalid-domain DNS timeout, and Node fetch reportingUND_ERR_SOCKETinstead ofENOTFOUND.Fixes #6392