Skip to content

Commit e4198ed

Browse files
authored
fix: fix list with no items looping forever (#3560)
* fix: fix list with no items looping forever * add test
1 parent 10020d0 commit e4198ed

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Tokenizer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ export class _Tokenizer {
418418
if (lastItem) {
419419
lastItem.raw = lastItem.raw.trimEnd();
420420
lastItem.text = lastItem.text.trimEnd();
421+
} else {
422+
// not a list since there were no items
423+
return;
421424
}
422425
list.raw = list.raw.trimEnd();
423426

test/unit/marked.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ describe('marked unit', () => {
127127
assert.strictEqual(html, '<p>Not Underlined A</p>\n<u>Underlined B</u>\n<p>Not Underlined C\n:Not Underlined D</p>\n');
128128
});
129129

130+
it('should not return list if no items', () => {
131+
const noHr = {
132+
tokenizer: {
133+
hr() {
134+
return undefined;
135+
},
136+
},
137+
};
138+
marked.use(noHr);
139+
const markdown = '- - -';
140+
const html = marked.parse(markdown);
141+
assert.strictEqual(html, '<p>- - -</p>\n');
142+
});
143+
130144
it('should use custom inline tokenizer + renderer extensions', () => {
131145
const underline = {
132146
name: 'underline',

0 commit comments

Comments
 (0)