Skip to content

Fix TypeError in MiddleWordEm extra when options was None (#627) #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [pull #622] Add missing block tags to regex (#620)
- [pull #623] Don't escape plus signs in URLs (#621)
- [pull #626] Fix XSS when encoding incomplete tags (#625)
- [pull #628] Fix TypeError in MiddleWordEm extra when options was None (#627)


## python-markdown2 2.5.3
Expand Down
6 changes: 4 additions & 2 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ class ItalicAndBoldProcessor(Extra):
strong_re = Markdown._strong_re
em_re = Markdown._em_re

def __init__(self, md: Markdown, options: dict):
def __init__(self, md: Markdown, options: Optional[dict]):
super().__init__(md, options)
self.hash_table = {}

Expand Down Expand Up @@ -3293,7 +3293,7 @@ class MiddleWordEm(ItalicAndBoldProcessor):
name = 'middle-word-em'
order = (CodeFriendly,), (Stage.ITALIC_AND_BOLD,)

def __init__(self, md: Markdown, options: Union[dict, bool]):
def __init__(self, md: Markdown, options: Union[dict, bool, None]):
'''
Args:
md: the markdown instance
Expand All @@ -3304,6 +3304,8 @@ def __init__(self, md: Markdown, options: Union[dict, bool]):
'''
if isinstance(options, bool):
options = {'allowed': options}
else:
options = options or {}
options.setdefault('allowed', True)
super().__init__(md, options)

Expand Down
1 change: 1 addition & 0 deletions test/tm-cases/middle_word_em_issue627.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>abc<em>def</em>ghi</p>
1 change: 1 addition & 0 deletions test/tm-cases/middle_word_em_issue627.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{'extras': {'middle-word-em': None}}
1 change: 1 addition & 0 deletions test/tm-cases/middle_word_em_issue627.text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc_def_ghi