Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def convert_img(
return alt

# Remove dataURIs
if src.startswith("data:") and not self.options["keep_data_uris"]:
if src.lower().startswith("data:") and not self.options["keep_data_uris"]:
src = src.split(",")[0] + "..."

return "![%s](%s%s)" % (alt, src, title_part)
Expand Down
15 changes: 15 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ def test_data_uris() -> None:
assert data == b"Hello, World!"


def test_uppercase_data_image_uri_is_truncated_by_default() -> None:
markitdown = MarkItDown()
html = b'<html><body><img alt="dot" src="DATA:image/png;base64,AAAA"></body></html>'
stream_info = StreamInfo(mimetype="text/html", extension=".html")

result = markitdown.convert_stream(io.BytesIO(html), stream_info=stream_info)
assert result.markdown == "![dot](DATA:image/png;base64...)"
assert "AAAA" not in result.markdown

result = markitdown.convert_stream(
io.BytesIO(html), stream_info=stream_info, keep_data_uris=True
)
assert result.markdown == "![dot](DATA:image/png;base64,AAAA)"


def test_file_uris() -> None:
# Test file URI with an empty host
file_uri = "file:///path/to/file.txt"
Expand Down