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
1 change: 1 addition & 0 deletions packages/markitdown/src/markitdown/_uri_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def parse_data_uri(uri: str) -> Tuple[str | None, Dict[str, str], bytes]:
if uri[:5].lower() != "data:":
raise ValueError("Not a data URI")

uri = uri.partition("#")[0]
header, _, data = uri.partition(",")
if not _:
raise ValueError("Malformed data URI, missing ',' separator")
Expand Down
21 changes: 21 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ def test_data_uris() -> None:
assert data == b"Hello, World!"


@pytest.mark.parametrize(
"uri, expected",
[
("data:text/plain,Hello#section", "Hello"),
("data:text/plain;base64,SGVsbG8h#AAAA", "Hello!"),
("data:text/plain,Hello%23section", "Hello#section"),
("data:text/plain,Hello#", "Hello"),
("data:text/plain,Hello?query", "Hello?query"),
("data:text/plain;base64,SGVsbG8=#section", "Hello"),
],
)
@pytest.mark.parametrize("public_api", [False, True])
def test_data_uri_fragments(uri: str, expected: str, public_api: bool) -> None:
if public_api:
actual = MarkItDown(enable_plugins=False).convert_uri(uri).text_content
else:
actual = parse_data_uri(uri)[2].decode("ascii")

assert actual == expected


def test_file_uris() -> None:
expected_path = os.path.abspath("/path/to/file.txt")

Expand Down