Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion markdown_it/rules_block/heading.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def heading(state: StateBlock, startLine: int, endLine: int, silent: bool) -> bo
if state.is_code_block(startLine):
return False

ch: str | None = state.src[pos]
try:
ch: str | None = state.src[pos]
except IndexError:
return False

if ch != "#" or pos >= maximum:
return False
Expand Down
5 changes: 4 additions & 1 deletion markdown_it/rules_block/html_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def html_block(state: StateBlock, startLine: int, endLine: int, silent: bool) ->
if not state.md.options.get("html", None):
return False

if state.src[pos] != "<":
try:
if state.src[pos] != "<":
return False
except IndexError:
return False

lineText = state.src[pos:maximum]
Expand Down
20 changes: 20 additions & 0 deletions tests/test_fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ def test_fuzzing(raw_input, expected):
md = MarkdownIt()
md.parse(raw_input)
assert md.render(raw_input) == expected


# Input that ends on a blockquote marker while a table is open inside the quote
# used to raise ``IndexError: string index out of range`` from the terminator
# rules ``html_block`` and ``heading`` (gh-issue 415). ``table`` must be enabled
# for the terminator rules to run on that line.
GH_415_INPUT = "> | a | b |\n> |---|---|\n>"


def test_gh_415_table_in_blockquote_at_eof_html_block() -> None:
# html_block runs first, so with html enabled it is the rule that used to raise
md = MarkdownIt().enable("table")
md.render(GH_415_INPUT) # must not raise IndexError


def test_gh_415_table_in_blockquote_at_eof_heading() -> None:
# with html disabled, html_block bails at its options check and heading is
# the terminator rule that used to raise
md = MarkdownIt("commonmark", {"html": False}).enable("table")
md.render(GH_415_INPUT) # must not raise IndexError