[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:
co-authored by
Claude Fable 5
parent
453f01783d
commit
d02df748bf
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user