Skip to content

Commit 18c21d7

Browse files
committed
fix(directive): use correct file path for include directive
1 parent ae850f5 commit 18c21d7

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎src/mistune/directives/include.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def parse(
7272

7373
ext = os.path.splitext(dest)[1]
7474
if ext in {".md", ".markdown", ".mkd"}:
75+
content = content.replace("\r\n", "\n").replace("\r", "\n")
7576
new_state = state.child_state(content)
7677
previous_file = new_state.env.get("__file__")
7778
new_state.env["__file__"] = dest

‎tests/test_security_include.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def test_include_rejects_circular_references(self):
5858
with tempfile.TemporaryDirectory() as tmpdir:
5959
a = os.path.join(tmpdir, "a.md")
6060
b = os.path.join(tmpdir, "b.md")
61-
with open(a, "w") as f:
62-
f.write(".. include:: b.md\n")
63-
with open(b, "w") as f:
64-
f.write(".. include:: a.md\n")
61+
with open(a, "wb") as f:
62+
f.write(b".. include:: b.md\r\n")
63+
with open(b, "wb") as f:
64+
f.write(b".. include:: a.md\r\n")
6565

6666
md = create_markdown(plugins=[RSTDirective([Include()])])
6767
html = md.read(a)[0]

0 commit comments

Comments
 (0)