Changeset: Add range checks to `makeSplice`

pull/5330/head
Richard Hansen 2021-12-12 23:50:48 -05:00
parent fdf1fdbc23
commit 30d68df396
1 changed files with 2 additions and 0 deletions

View File

@ -1491,6 +1491,8 @@ exports.identity = (N) => exports.pack(N, N, '', '');
* @returns {string}
*/
exports.makeSplice = (orig, start, ndel, ins, attribs, pool) => {
if (start < 0) throw new RangeError(`start index must be non-negative (is ${start})`);
if (ndel < 0) throw new RangeError(`characters to delete must be non-negative (is ${ndel})`);
if (start >= orig.length) start = orig.length - 1;
if (ndel > orig.length - start) ndel = orig.length - start;
const deleted = orig.substring(start, start + ndel);