2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

fix: prevent RangeError when using large Buffers (#6961)

This commit is contained in:
Manish Sahani
2025-07-15 23:48:24 +05:30
committed by GitHub
parent 6161947d9d
commit a2214ca1bc
2 changed files with 70 additions and 0 deletions
+34
View File
@@ -80,4 +80,38 @@ describe('utils', function (){
assert.strictEqual(JSON.stringify(jsonObject), JSON.stringify({x: 1, y:2, obj: {ok: 1}}))
});
});
describe('Buffer RangeError Fix', function () {
it('should handle large Buffer in isEmptyObject without RangeError', function () {
// Create a big buffer that used to cause the error
const largeBuffer = Buffer.alloc(1024 * 1024 * 200); // 200MB
// This used to throw: RangeError: Invalid array length
// Now it should work fine
const result = utils.isEmptyObject(largeBuffer);
// Buffer should not be considered an empty object
assert.strictEqual(result, false);
});
it('should handle large Buffer in forEach without RangeError', function () {
const largeBuffer = Buffer.alloc(1024 * 1024 * 200); // 200MB
let count = 0;
// This should skip the buffer (not iterate through it)
utils.forEach(largeBuffer, () => count++);
// Count should be 0 because forEach skips Buffers
assert.strictEqual(count, 0);
});
it('should handle large Buffer in findKey without RangeError', function () {
const largeBuffer = Buffer.alloc(1024 * 1024 * 200); // 200MB
// Should return null for Buffers
const result = utils.findKey(largeBuffer, 'test');
assert.strictEqual(result, null);
});
});
});