fix: match literal MIME types with regex metacharacters in DocumentTypeRouter - #11973
Merged
anakin87 merged 3 commits intoJul 13, 2026
Merged
Conversation
…peRouter DocumentTypeRouter compiles each declared MIME type as a regex and matches with `pattern.fullmatch`. A standard IANA type containing a regex metacharacter, most notably the '+' in 'image/svg+xml', is thus misinterpreted: 'svg+xml' means 'svg' with one-or-more 'g', so 'image/svg+xml' documents never match and fall into 'unclassified'. Match declared MIME types by exact equality first, then fall back to regex, so literal types with metacharacters route correctly while regex patterns like 'audio/.*' keep working. The output bucket key is unchanged (equal to the declared string), so declared output types are unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@chuenchen309 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
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.
Problem
DocumentTypeRoutercompiles each declared MIME type as a regex and matches withpattern.fullmatch(mime_type). A standard IANA type that contains a regexmetacharacter is therefore misinterpreted. The clearest case is the
+inimage/svg+xml: as a regex,svg+xmlmeanssvfollowed by one-or-moregfollowed by
xml, so an actualimage/svg+xmldocument never matches and landsin
unclassified.Fix
Match declared MIME types by exact equality first, then fall back to regex.
This routes literal types with metacharacters correctly while preserving regex
patterns such as
audio/.*. The output bucket key is unchanged (it equals thedeclared string, as before), so declared output types are unaffected. This
mirrors how
FileTypeRouterhandles the same situation.Tests
Added
test_run_with_literal_mime_type_containing_regex_metacharacterintest/components/routers/test_document_type_router.py, assertingimage/svg+xmlroutes to its own bucket and a coexisting
audio/.*regex pattern stillmatches. Fails before the change, passes after. All 19 router tests pass.
ruff check/ruff format --checkpass. Added a release note.Disclosure: I used AI assistance (Claude) to find this regex-metacharacter
routing bug and draft the test. I reviewed the change, ran the suite, and take
responsibility for its correctness.