From 30d68df3966c544ba23f4edb63785d17252968cf Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 12 Dec 2021 23:50:48 -0500 Subject: [PATCH] Changeset: Add range checks to `makeSplice` --- src/static/js/Changeset.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/static/js/Changeset.js b/src/static/js/Changeset.js index f753c791..81032b58 100644 --- a/src/static/js/Changeset.js +++ b/src/static/js/Changeset.js @@ -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);