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
6 changes: 3 additions & 3 deletions packages/markitdown/src/markitdown/_uri_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def parse_data_uri(uri: str) -> Tuple[str | None, Dict[str, str], bytes]:

is_base64 = False
# Ends with base64?
if parts[-1] == "base64":
if parts[-1].lower() == "base64":
parts.pop()
is_base64 = True

Expand All @@ -43,9 +43,9 @@ def parse_data_uri(uri: str) -> Tuple[str | None, Dict[str, str], bytes]:
# Handle key=value pairs in the middle
if "=" in part:
key, value = part.split("=", 1)
attributes[key] = value
attributes[key.lower()] = value
elif len(part) > 0:
attributes[part] = ""
attributes[part.lower()] = ""

content = base64.b64decode(data) if is_base64 else unquote_to_bytes(data)

Expand Down
7 changes: 7 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ def test_data_uris() -> None:
assert attributes["charset"] == "utf-8"
assert data == b"Hello, World!"

data_uri = "data:text/plain;CHARSET=utf-8;BASE64,SGVsbG8sIFdvcmxkIQ=="
mime_type, attributes, data = parse_data_uri(data_uri)
assert mime_type == "text/plain"
assert len(attributes) == 1
assert attributes["charset"] == "utf-8"
assert data == b"Hello, World!"

data_uri = "data:,Hello%2C%20World%21"
mime_type, attributes, data = parse_data_uri(data_uri)
assert mime_type is None
Expand Down