Skip to content

Commit

Permalink
Fixes #409: IndexError on empty strong mark on version. (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alir3z4 authored Feb 27, 2024
1 parent ff0db81 commit b053a5a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 33 deletions.
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

7 changes: 7 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Unreleased
==========
----

* Fixes #409: IndexError on empty strong mark.


2024.2.25
=========
----
Expand Down
4 changes: 4 additions & 0 deletions html2text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ 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]
):
strong = " " + self.strong_mark
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions test/test_html2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,12 @@ def _skip_certain_tags(h2t, tag, attrs, start):
"some <i>italics</i> 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>B</b> <i>C</i>."
assert h.handle(string) == "A B _C_.\n\n"

0 comments on commit b053a5a

Please sign in to comment.