2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

fix(headers): trim trailing CRLF in normalized header values (#7456)

This commit is contained in:
Eve
2026-03-01 10:48:03 -05:00
committed by GitHub
parent f17a787026
commit 688826facd
2 changed files with 27 additions and 1 deletions
+3 -1
View File
@@ -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) {
+24
View File
@@ -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();