diff --git a/python/semantic_kernel/contents/utils/data_uri.py b/python/semantic_kernel/contents/utils/data_uri.py index 22f514fac9b0..01ef7d267147 100644 --- a/python/semantic_kernel/contents/utils/data_uri.py +++ b/python/semantic_kernel/contents/utils/data_uri.py @@ -135,7 +135,7 @@ def from_data_uri(cls: type[_T], data_uri: str | Url, default_mime_type: str = " if not data or "," not in data: raise ContentInitializationError("Invalid data uri format. The data is missing.") - pattern = "(((?P[a-zA-Z]+/[a-zA-Z-]+)(?P(;[a-zA-Z0-9]+=+[a-zA-Z0-9]+)*))?(;+(?P.*)))?(,(?P.*))" # noqa: E501 + pattern = "(((?P[a-zA-Z]+/[a-zA-Z0-9!#$&^_.+-]+)(?P(;[a-zA-Z0-9]+=+[a-zA-Z0-9]+)*))?(;+(?P.*)))?(,(?P.*))" # noqa: E501 match = re.match(pattern, data) if not match: raise ContentInitializationError("Invalid data uri format.") diff --git a/python/tests/unit/contents/test_data_uri.py b/python/tests/unit/contents/test_data_uri.py index fc98679a9765..6a7721ecd0f0 100644 --- a/python/tests/unit/contents/test_data_uri.py +++ b/python/tests/unit/contents/test_data_uri.py @@ -39,6 +39,24 @@ "base64", id="basic_binary", ), + pytest.param( + "data:image/svg+xml;base64,PHN2Zy8+", + b"", + "PHN2Zy8+", + "image/svg+xml", + {}, + "base64", + id="structured_suffix", + ), + pytest.param( + "data:application/vnd.api+json;base64,e30=", + b"{}", + "e30=", + "application/vnd.api+json", + {}, + "base64", + id="vendor_subtype", + ), pytest.param( "data:text/plain;base64,U29t\r\nZQ==\t", b"Some",