fix: strict RFC 2397 regex in _parse_base64_data_uri to reject SSE data#1524
Open
MoonSangJin wants to merge 1 commit intolangfuse:mainfrom
Open
fix: strict RFC 2397 regex in _parse_base64_data_uri to reject SSE data#1524MoonSangJin wants to merge 1 commit intolangfuse:mainfrom
MoonSangJin wants to merge 1 commit intolangfuse:mainfrom
Conversation
1999f69 to
2e0dfea
Compare
…identifying SSE data
_parse_base64_data_uri previously used a loose startswith("data:") check,
which caused SSE data (e.g., "data: {...}") to be incorrectly processed
as base64 data URIs, resulting in spurious error logs.
Replace the manual parsing with a strict regex that requires the full
data:[<mediatype>][;params];base64,<data> format. Non-matching inputs
now return (None, None) cleanly without error logging.
Closes langfuse/langfuse#5659
2e0dfea to
13a4f5c
Compare
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
_parse_base64_data_uripreviously used a loosestartswith("data:")check, which misidentified SSE data (e.g.,"data: {'foo': 'bar'}") as base64 data URIs, causing spurious error logsdata:[<mediatype>][;params];base64,<data>format(None, None)cleanly without error loggingTest plan
tests/test_issue_5659.pycovering SSE data, valid data URIs, MIME params, missing MIME type, empty/invalid stringstests/test_media.pyunit tests passruff check,ruff format,mypyall passCloses langfuse/langfuse#5659