From ec999bf43c10f30e4cbc6ff8ca30c1998e3aab97 Mon Sep 17 00:00:00 2001 From: Arve Seljebu Date: Thu, 30 Dec 2021 21:36:35 +0100 Subject: [PATCH] issue #128 crashes on {} in start of list item tests with shift -1 was rolling around to end of array when matching first child token --- index.js | 6 ++++++ test.js | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8d8e19f..c44c7cf 100644 --- a/index.js +++ b/index.js @@ -57,6 +57,12 @@ function test(tokens, i, t) { let ii = t.shift !== undefined ? i + t.shift : t.position; + + if (t.shift !== undefined && ii < 0) { + // we should never shift to negative indexes (rolling around to back of array) + return res; + } + let token = get(tokens, ii); // supports negative ii diff --git a/test.js b/test.js index bffdae9..a25ca18 100644 --- a/test.js +++ b/test.js @@ -390,11 +390,17 @@ function describeTestsWithOptions(options, postText) { assert.equal(md.render(replaceDelimiters(src, options)), expected); }); - it(replaceDelimiters('should support multiple classes for
', options), () => { + it('should support multiple classes for
', () => { src = '--- {.a .b}'; expected = '
\n'; assert.equal(md.render(replaceDelimiters(src, options)), expected); }); + + it(replaceDelimiters('should not crash on {#ids} in front of list items', options), () => { + src = '- {#ids} [link](./link)'; + expected = replaceDelimiters('\n', options); + assert.equal(md.render(replaceDelimiters(src, options)), expected); + }); }); }