[Bugfix] Accept RFC 2397 parameters in base64 data URLs (#48973)

Signed-off-by: Thomas Fahrner <thomas.fahrner@parasail.io>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Thomas Fahrner
2026-07-24 08:23:08 -07:00
committed by GitHub
co-authored by Claude Fable 5
parent 453f01783d
commit d02df748bf
2 changed files with 46 additions and 4 deletions
+8 -4
View File
@@ -302,14 +302,18 @@ class MediaConnector:
media_io: MediaIO[_M],
) -> _M: # type: ignore[type-var]
# Format per RFC 2397:
# data:[<mediatype>][;base64],<data>
data_spec, data = url[5:].split(",", 1)
media_type, data_type = data_spec.split(";", 1)
# data:[<mediatype>][;<param>=<value>]*[;base64],<data>
data_spec, sep, data = url[5:].partition(",")
if not sep:
msg = f"Invalid data URL {url[:32]!r}: missing ',' separator."
raise ValueError(msg)
if data_type != "base64":
media_type, sep, encoding = data_spec.rpartition(";")
if not sep or encoding != "base64":
msg = "Only base64 data URLs are supported for now."
raise NotImplementedError(msg)
media_type = media_type.partition(";")[0]
return media_io.load_base64(media_type, data)
def _load_file_url(