From 76e5edb3575d9a67b70b022f898ea0d0accb6434 Mon Sep 17 00:00:00 2001 From: alheiveea Date: Wed, 9 Jul 2025 22:08:47 +0200 Subject: [PATCH] limit colspan values to range [1, 1000] (#232) --- markdownify/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index e901d10..148d340 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -735,13 +735,13 @@ class MarkdownConverter(object): def convert_td(self, el, text, parent_tags): colspan = 1 if 'colspan' in el.attrs and el['colspan'].isdigit(): - colspan = int(el['colspan']) + colspan = max(1, min(1000, int(el['colspan']))) return ' ' + text.strip().replace("\n", " ") + ' |' * colspan def convert_th(self, el, text, parent_tags): colspan = 1 if 'colspan' in el.attrs and el['colspan'].isdigit(): - colspan = int(el['colspan']) + colspan = max(1, min(1000, int(el['colspan']))) return ' ' + text.strip().replace("\n", " ") + ' |' * colspan def convert_tr(self, el, text, parent_tags): @@ -762,7 +762,7 @@ class MarkdownConverter(object): full_colspan = 0 for cell in cells: if 'colspan' in cell.attrs and cell['colspan'].isdigit(): - full_colspan += int(cell["colspan"]) + full_colspan += max(1, min(1000, int(cell['colspan']))) else: full_colspan += 1 if ((is_headrow