Skip to content

Commit 9595618

Browse files
committed
prevent very large headline prefixes
for example: `<h9999999>` could crash the conversion. fixes #143
1 parent fe8a821 commit 9595618

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

Diff for: markdownify/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ def convert_hn(self, n, el, text, convert_as_inline):
315315
if convert_as_inline:
316316
return text
317317

318+
# prevent MemoryErrors in case of very large n
319+
n = max(1, min(6, n))
320+
318321
style = self.options['heading_style'].lower()
319322
text = text.strip()
320323
if style == UNDERLINED and n <= 2:

Diff for: tests/test_conversions.py

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def test_hn():
133133
assert md('<h4>Hello</h4>') == '\n#### Hello\n\n'
134134
assert md('<h5>Hello</h5>') == '\n##### Hello\n\n'
135135
assert md('<h6>Hello</h6>') == '\n###### Hello\n\n'
136+
assert md('<h10>Hello</h10>') == md('<h6>Hello</h6>')
136137

137138

138139
def test_hn_chained():

0 commit comments

Comments
 (0)