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
4 changes: 2 additions & 2 deletions packages/markitdown/src/markitdown/_uri_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
from typing import Tuple, Dict
from urllib.request import url2pathname
from urllib.parse import urlparse, unquote_to_bytes
from urllib.parse import unquote, urlparse, unquote_to_bytes


def _is_unc_or_device_path(path: str) -> bool:
Expand Down Expand Up @@ -66,7 +66,7 @@ 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.lower()] = value
attributes[key.lower()] = unquote(value)
elif len(part) > 0:
attributes[part.lower()] = ""

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

data_uri = "data:text/plain;charset=utf%2D8,Hello%2C%20World%21"
mime_type, attributes, data = parse_data_uri(data_uri)
assert mime_type == "text/plain"
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"
Expand Down