Skip to content

Commit 80b3e85

Browse files
committed
refactor: isolate inline parser state bounds
1 parent 7b0194c commit 80b3e85

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/mistune/core.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ def copy(self) -> "InlineState":
151151
state.in_image = self.in_image
152152
state.image_depth = self.image_depth
153153
state.in_link = self.in_link
154-
state.no_link_before = self.no_link_before
155-
state.no_image_before = self.no_image_before
156154
state.link_brackets = self.link_brackets
157155
state.link_ranges = self.link_ranges
158156
state.formatting_no_end = self.formatting_no_end

src/mistune/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _parse_link_href(
146146
if src[pos] == "<":
147147
href, href_pos = _parse_angle_link_href(src, pos)
148148
if href is None:
149-
return None, None, len(src)
149+
return None, None, pos
150150
assert href_pos is not None
151151
return href, href_pos, href_pos
152152
if block and src[pos] in ASCII_WHITESPACE:

src/mistune/inline_parser.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -884,14 +884,6 @@ def _emphasis_depth(tokens: List[Dict[str, Any]]) -> int:
884884
return max_depth
885885

886886

887-
def _has_strong_enabled(parts: List[Dict[str, Any]], opener: _Delimiter, closer: _Delimiter) -> bool:
888-
return _has_strong_enabled_at(parts, opener.index, closer.index)
889-
890-
891-
def _has_emphasis_enabled(parts: List[Dict[str, Any]], opener: _Delimiter, closer: _Delimiter) -> bool:
892-
return _has_emphasis_enabled_at(parts, opener.index, closer.index)
893-
894-
895887
def _has_strong_enabled_at(parts: List[Dict[str, Any]], opener_index: int, closer_index: int) -> bool:
896888
return len(_text_raw(parts[opener_index])) >= 2 and len(_text_raw(parts[closer_index])) >= 2
897889

tests/test_security_edge_cases.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,17 @@ def render(size):
8686
large = _best_time(render, 4000)
8787

8888
self.assertLess(large, small * 3 + 0.05)
89+
90+
def test_failed_parent_destination_does_not_hide_nested_images(self):
91+
md = create_markdown()
92+
self.assertEqual(
93+
md("[](foo( [outer ![inner](url)](/outer)"),
94+
'<p>[](foo( <a href="/outer">outer <img src="url" alt="inner" /></a></p>\n',
95+
)
96+
97+
def test_failed_angle_destination_does_not_hide_later_links(self):
98+
md = create_markdown()
99+
self.assertEqual(
100+
md("[]( <foo [bar](/url)"),
101+
'<p>[]( &lt;foo <a href="/url">bar</a></p>\n',
102+
)

0 commit comments

Comments
 (0)