Skip to content

Commit 947d4c6

Browse files
authored
🐛 FIX: MarkdownIt.render; don't copy empty env arg (#77)
1 parent b533d6d commit 947d4c6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

markdown_it/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def render(self, src: str, env: Optional[AttrDict] = None) -> Any:
240240
But you will not need it with high probability. See also comment
241241
in [[MarkdownIt.parse]].
242242
"""
243-
env = env or AttrDict()
243+
if env is None:
244+
env = AttrDict()
244245
return self.renderer.render(self.parse(src, env), self.options, env)
245246

246247
def parseInline(self, src: str, env: Optional[AttrDict] = None) -> List[Token]:

tests/test_api/test_main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from markdown_it import MarkdownIt
22
from markdown_it.token import Token
33
from markdown_it.rules_core import StateCore
4+
from markdown_it.utils import AttrDict
45

56

67
def test_get_rules():
@@ -250,3 +251,16 @@ def test_noneState():
250251

251252
# Check that we can process None str with empty env and block_tokens
252253
md.core.process(state)
254+
255+
256+
def test_empty_env():
257+
"""Test that an empty `env` is mutated, not copied and mutated."""
258+
md = MarkdownIt()
259+
260+
env = AttrDict()
261+
md.render("[foo]: /url\n[foo]", env)
262+
assert "references" in env
263+
264+
env = AttrDict()
265+
md.parse("[foo]: /url\n[foo]", env)
266+
assert "references" in env

0 commit comments

Comments
 (0)