Skip to content

Base64 data URIs fail or decode incorrect bytes when their payload is percent-encoded #2481

Open

Description

@adity982

Bug

On current main cc0ca9e, percent-encoded characters in a base64 data URI reach the base64 decoder without URL decoding. Some valid inputs raise binascii.Error; others silently produce incorrect bytes.

No network or fixture is needed (Python 3.12):

from markitdown._uri_utils import parse_data_uri

print(parse_data_uri("data:text/plain;base64,SGVsbG8%3D"))
# Expected: ('text/plain', {}, b'Hello')
# Actual: binascii.Error

print(parse_data_uri("data:application/octet-stream;base64,%2B/8="))
# Expected bytes: b'\xfb\xff'
# Actual bytes: b'\xd8\x1f\xfc'

MarkItDown.convert_uri also fails on URL-escaped base64 payloads. Raw base64 and non-base64 data URIs already work and should keep their behavior. RFC 2397 section 3 defines the data field using URL characters; decoding those escapes must precede base64 decoding. The new regression suite reports 16 failures and 2 passes against unchanged production code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions