2016-08-23 14:16:45 -07:00
|
|
|
'use strict';
|
2025-05-07 18:28:20 +02:00
|
|
|
|
|
|
|
const common = require('../common');
|
2018-03-21 01:02:49 +05:30
|
|
|
|
2023-09-28 14:50:20 +02:00
|
|
|
// This test ensures that Node.js throws an Error when trying to convert a
|
|
|
|
// large buffer into a string.
|
2018-03-21 01:02:49 +05:30
|
|
|
// Regression test for https://github.com/nodejs/node/issues/649.
|
|
|
|
|
2025-05-07 18:28:20 +02:00
|
|
|
if (!common.enoughTestMem) {
|
|
|
|
common.skip('skipped due to memory requirements');
|
|
|
|
}
|
|
|
|
|
2016-08-23 14:16:45 -07:00
|
|
|
const assert = require('assert');
|
2023-09-28 14:50:20 +02:00
|
|
|
const {
|
2025-05-07 20:31:21 +01:00
|
|
|
SlowBuffer,
|
2023-09-28 14:50:20 +02:00
|
|
|
constants: {
|
|
|
|
MAX_STRING_LENGTH,
|
|
|
|
},
|
|
|
|
} = require('buffer');
|
2016-08-23 14:16:45 -07:00
|
|
|
|
2023-09-28 14:50:20 +02:00
|
|
|
const len = MAX_STRING_LENGTH + 1;
|
2019-12-25 18:02:16 +01:00
|
|
|
const message = {
|
2023-09-28 14:50:20 +02:00
|
|
|
code: 'ERR_STRING_TOO_LONG',
|
|
|
|
name: 'Error',
|
2019-12-25 18:02:16 +01:00
|
|
|
};
|
2016-12-13 12:51:01 +08:00
|
|
|
assert.throws(() => Buffer(len).toString('utf8'), message);
|
2025-05-07 20:31:21 +01:00
|
|
|
assert.throws(() => SlowBuffer(len).toString('utf8'), message);
|
2016-12-13 12:51:01 +08:00
|
|
|
assert.throws(() => Buffer.alloc(len).toString('utf8'), message);
|
|
|
|
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message);
|
|
|
|
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message);
|