mirror of
https://github.com/axios/axios.git
synced 2026-04-11 14:21:59 +08:00
fix(headers): trim trailing CRLF in normalized header values (#7456)
This commit is contained in:
parent
f17a787026
commit
688826facd
@ -14,7 +14,9 @@ function normalizeValue(value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return utils.isArray(value) ? value.map(normalizeValue) : String(value);
|
||||
return utils.isArray(value)
|
||||
? value.map(normalizeValue)
|
||||
: String(value).replace(/[\r\n]+$/, '');
|
||||
}
|
||||
|
||||
function parseTokens(str) {
|
||||
|
||||
@ -83,6 +83,30 @@ describe('AxiosHeaders', function () {
|
||||
assert.strictEqual(headers.get('x'), '123');
|
||||
});
|
||||
|
||||
it('should trim trailing CRLF from plain object header values', function () {
|
||||
const headers = new AxiosHeaders();
|
||||
|
||||
headers.set({
|
||||
'cache-control': 'no-cache\r',
|
||||
expires: '-1\r\n',
|
||||
});
|
||||
|
||||
assert.strictEqual(headers.get('cache-control'), 'no-cache');
|
||||
assert.strictEqual(headers.get('expires'), '-1');
|
||||
});
|
||||
|
||||
it('should trim trailing CRLF from iterable header values', function () {
|
||||
const headers = new AxiosHeaders();
|
||||
|
||||
headers.set(new Map([
|
||||
['content-type', 'application/json; charset=utf-8\r'],
|
||||
['pragma', 'no-cache\r\n'],
|
||||
]));
|
||||
|
||||
assert.strictEqual(headers.get('content-type'), 'application/json; charset=utf-8');
|
||||
assert.strictEqual(headers.get('pragma'), 'no-cache');
|
||||
});
|
||||
|
||||
it('should support setting multiple header values from an iterable source', function () {
|
||||
if (nodeMajorVersion < 18) {
|
||||
this.skip();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user