mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-22 16:23:12 +08:00
Fix empty Markdown document parsing (#18503)
## Summary - treat empty Markdown binaries as in-memory content instead of local file paths - add a regression test ensuring empty content does not access the filesystem Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -894,7 +894,7 @@ class Markdown(MarkdownParser):
|
||||
|
||||
def __call__(self, filename, binary=None, separate_tables=True, delimiter=None, return_section_images=False):
|
||||
"""Parse markdown into text sections and optional standalone table chunks."""
|
||||
if binary:
|
||||
if binary is not None:
|
||||
encoding = find_codec(binary)
|
||||
txt = binary.decode(encoding, errors="ignore")
|
||||
else:
|
||||
|
||||
@@ -91,6 +91,21 @@ def parser(naive_module):
|
||||
return naive_module.Markdown(128)
|
||||
|
||||
|
||||
@pytest.mark.p1
|
||||
def test_parses_empty_binary_without_opening_filename(parser):
|
||||
with patch("builtins.open") as open_file:
|
||||
sections, tables, section_images = parser(
|
||||
"empty-document.md",
|
||||
binary=b"",
|
||||
return_section_images=True,
|
||||
)
|
||||
|
||||
open_file.assert_not_called()
|
||||
assert sections == []
|
||||
assert tables == []
|
||||
assert section_images == []
|
||||
|
||||
|
||||
@pytest.mark.p1
|
||||
def test_blocks_internal_url_without_fetching(parser):
|
||||
"""A markdown image pointing at an internal host must never be requested."""
|
||||
|
||||
Reference in New Issue
Block a user