mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix(headers): trim trailing CRLF in normalized header values (#7456)
This commit is contained in:
@@ -14,7 +14,9 @@ function normalizeValue(value) {
|
|||||||
return 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) {
|
function parseTokens(str) {
|
||||||
|
|||||||
@@ -83,6 +83,30 @@ describe('AxiosHeaders', function () {
|
|||||||
assert.strictEqual(headers.get('x'), '123');
|
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 () {
|
it('should support setting multiple header values from an iterable source', function () {
|
||||||
if (nodeMajorVersion < 18) {
|
if (nodeMajorVersion < 18) {
|
||||||
this.skip();
|
this.skip();
|
||||||
|
|||||||
Reference in New Issue
Block a user