From 2520aeafc240b621d03ce3f470d58475b56fb0f5 Mon Sep 17 00:00:00 2001 From: Alireza Savand Date: Mon, 26 Feb 2024 23:18:32 +0300 Subject: [PATCH 1/6] Fix `IndexError` on empty strong mark on version. --- html2text/__init__.py | 1 + test/test_html2text.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/html2text/__init__.py b/html2text/__init__.py index 937ea9d..1a61607 100644 --- a/html2text/__init__.py +++ b/html2text/__init__.py @@ -438,6 +438,7 @@ def handle_tag( if ( start and self.preceding_data + and len(self.strong_mark) > 0 and self.preceding_data[-1] == self.strong_mark[0] ): strong = " " + self.strong_mark diff --git a/test/test_html2text.py b/test/test_html2text.py index ea86144..5db8971 100644 --- a/test/test_html2text.py +++ b/test/test_html2text.py @@ -240,3 +240,12 @@ def _skip_certain_tags(h2t, tag, attrs, start): "some italics too." ) assert ret == "this is a txt and this is a with text and some _italics_ too.\n\n" + + +def test_strong_emptied() -> None: + """When strong is being set to empty, it should not mark it.""" + h = html2text.HTML2Text() + h.emphasis_mark = "_" + h.strong_mark = "" + string = "A B C." + assert h.handle(string) == "A B _C_.\n\n" From 9c6fda19b6baa268ff86b093b6156d8acf544d39 Mon Sep 17 00:00:00 2001 From: Alireza Savand Date: Mon, 26 Feb 2024 23:35:20 +0300 Subject: [PATCH 2/6] Add some documentation to the new change. --- html2text/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/html2text/__init__.py b/html2text/__init__.py index 1a61607..bd28a9e 100644 --- a/html2text/__init__.py +++ b/html2text/__init__.py @@ -438,6 +438,9 @@ def handle_tag( if ( start and self.preceding_data + # When `self.strong_mark` is set to empty, the next condition + # will cause IndexError since it's trying to match the data + # with the first character of the `self.strong_mark`. and len(self.strong_mark) > 0 and self.preceding_data[-1] == self.strong_mark[0] ): From 120d3ec256bb50901477ae932f745ddf1999c309 Mon Sep 17 00:00:00 2001 From: Alireza Savand Date: Mon, 26 Feb 2024 23:35:46 +0300 Subject: [PATCH 3/6] Remove unused .travis.yml file as no longer being used. --- .travis.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fdc7048..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: python -cache: pip - -matrix: - include: - - python: 3.12 - env: TOXENV=black - - python: 3.12 - env: TOXENV=flake8 - - python: 3.12 - env: TOXENV=mypy - - python: 3.12 - env: TOXENV=isort - - python: 3.8 - env: TOXENV=py38 - - python: 3.9 - env: TOXENV=py39 - - python: 3.10 - env: TOXENV=py310 - - python: 3.11 - env: TOXENV=py310 - - python: 3.12 - env: TOXENV=py310 - - python: pypy3 - env: TOXENV=pypy3 - -install: - - pip install tox -script: - - tox -after_success: - - pip install coveralls - - coveralls From 63d1f119fdef684f022323d621e850dfc5926a21 Mon Sep 17 00:00:00 2001 From: Alireza Savand Date: Mon, 26 Feb 2024 23:36:07 +0300 Subject: [PATCH 4/6] Add "env" to be excluded from the flake8 and isort --- setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.cfg b/setup.cfg index 7b0fab2..d2d5921 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,10 +42,12 @@ html2text = py.typed [flake8] max_line_length = 88 extend-ignore = E203 +extend-exclude = env/ [isort] combine_as_imports = True profile = black +extend_skip = env/ [mypy] python_version = 3.8 From 776159b91086ce44832324e5e6a2d4fbe69f6f01 Mon Sep 17 00:00:00 2001 From: Alireza Savand Date: Mon, 26 Feb 2024 23:36:16 +0300 Subject: [PATCH 5/6] Add Changelog entry --- ChangeLog.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ChangeLog.rst b/ChangeLog.rst index 99d125d..7901026 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,3 +1,10 @@ +Unreleased +========== +---- + +* Fixe #409: IndexError on empty strong mark. + + 2024.2.25 ========= ---- From e22ff1c0d11e5f8b0e27a8050d825f0eb893a0fe Mon Sep 17 00:00:00 2001 From: Alireza Savand <591113+Alir3z4@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:05:44 +0300 Subject: [PATCH 6/6] Update ChangeLog.rst --- ChangeLog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.rst b/ChangeLog.rst index 7901026..48a62c1 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -2,7 +2,7 @@ Unreleased ========== ---- -* Fixe #409: IndexError on empty strong mark. +* Fixes #409: IndexError on empty strong mark. 2024.2.25