Handle audio data URL MIME variants#259
Open
fus3r wants to merge 1 commit into
Open
Conversation
fus3r
force-pushed
the
fix-audio-data-url-mime-prefix
branch
from
July 6, 2026 12:30
8247a2a to
76480fc
Compare
fus3r
marked this pull request as ready for review
July 6, 2026 12:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Audio data URL prefix stripping only matched word-only MIME subtypes. Valid data URLs such as
data:audio/x-wav;base64,...,data:audio/vnd.wave;base64,..., anddata:audio/wav;codec=pcm;base64,...were left untouched.That made audio parsing try to base64-decode the full data URL rather than the payload, so valid audio bytes failed with a base64 or audio-format error. This affected both
AudioChunk.to_openai()and tokenizer/audio parsing throughAudio.from_base64()/Audio.from_audio_chunk(). The same bytes worked when the MIME subtype was simplyaudio/wav.This broadens the audio data URL prefix match to allow MIME subtype punctuation and media-type parameters before
;base64,, and makesAudio.from_base64()reuse the same helper asAudioChunk.to_openai(). The parameter match avoids consuming semicolon separators, so malformed inputs with repeated semicolons do not trigger pathological backtracking. The payload and detected format are unchanged.Testing
pytest tests/test_converters.py tests/test_audio.py -qruff check src/mistral_common/protocol/instruct/chunk.py src/mistral_common/tokens/tokenizers/audio.py tests/test_converters.py tests/test_audio.pyruff format src/mistral_common/protocol/instruct/chunk.py src/mistral_common/tokens/tokenizers/audio.py tests/test_converters.py tests/test_audio.py --checkmypy src tests scriptspytest tests/ --ignore=tests/integrations -qpytest --doctest-modules ./src -qmkdocs build --strictpytest tests/integrations/ -qNo related issue. This follows the same audio conversion surface as #245.