mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
fix(headers): silently skip empty header names instead of throwing (#10875)
* fix(headers): silently skip empty header names instead of throwing Signed-off-by: Ravi <13908473+rkdfx@users.noreply.github.com> * chore: add suggested test headers length assert Signed-off-by: Ravi <13908473+rkdfx@users.noreply.github.com> * test(headers): cover whitespace-only header names --------- Signed-off-by: Ravi <13908473+rkdfx@users.noreply.github.com> Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
## Bug Fixes
|
||||
|
||||
- **AxiosHeaders:** Silently skip empty response header names emitted by some React Native Android responses instead of throwing. (**#6959**, **#10875**)
|
||||
- **Request Data:** Preserve enumerable symbol keys when merging plain request data before `transformRequest`. (**#6392**)
|
||||
|
||||
## Release Documentation TODO
|
||||
|
||||
@@ -89,7 +89,7 @@ class AxiosHeaders {
|
||||
const lHeader = normalizeHeader(_header);
|
||||
|
||||
if (!lHeader) {
|
||||
throw new Error('header name must be a non-empty string');
|
||||
return;
|
||||
}
|
||||
|
||||
const key = utils.findKey(self, lHeader);
|
||||
|
||||
@@ -146,6 +146,29 @@ describe('AxiosHeaders', () => {
|
||||
|
||||
assert.strictEqual(headers.get('x-name'), '请求Injected: true用户');
|
||||
});
|
||||
|
||||
// Regression: https://github.com/axios/axios/issues/6959
|
||||
it('should silently skip empty header names', () => {
|
||||
const headers = new AxiosHeaders();
|
||||
|
||||
assert.doesNotThrow(() => headers.set('', 'a'));
|
||||
assert.doesNotThrow(() => headers.set(' ', 'b'));
|
||||
assert.doesNotThrow(() => headers.set({ '': 'c', ' ': 'd', foo: 'bar' }));
|
||||
assert.doesNotThrow(() =>
|
||||
headers.set(
|
||||
new Map([
|
||||
['', 'e'],
|
||||
[' ', 'f'],
|
||||
['x', 'y'],
|
||||
])
|
||||
)
|
||||
);
|
||||
|
||||
assert.strictEqual(headers.has(''), false);
|
||||
assert.strictEqual(headers.get('foo'), 'bar');
|
||||
assert.strictEqual(headers.get('x'), 'y');
|
||||
assert.strictEqual(Object.keys(headers).length, 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support uppercase name mapping for names overlapped by class methods', () => {
|
||||
|
||||
Reference in New Issue
Block a user