Skip to content

Commit

Permalink
issue #128 crashes on {} in start of list item
Browse files Browse the repository at this point in the history
tests with shift -1 was rolling around to end of array
when matching first child token
  • Loading branch information
arve0 committed Dec 30, 2021
1 parent 0f595bd commit ec999bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 7 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,17 @@ function describeTestsWithOptions(options, postText) {
assert.equal(md.render(replaceDelimiters(src, options)), expected);
});

it(replaceDelimiters('should support multiple classes for <hr>', options), () => {
it('should support multiple classes for <hr>', () => {
src = '--- {.a .b}';
expected = '<hr class="a b">\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('<ul>\n<li>{#ids} <a href="./link">link</a></li>\n</ul>\n', options);
assert.equal(md.render(replaceDelimiters(src, options)), expected);
});
});
}

Expand Down

0 comments on commit ec999bf

Please sign in to comment.