Repository navigation
Updates for content type detection - #101
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The ZIP refinement incorrectly accepts non-archive OpenDocument flat-XML MIME types.
1 open finding
What changed in this PR
Improves MIME detection by refining sniffed text and ZIP types using file extensions.
Changes:
- Adds Markdown and ZIP-based document MIME mappings.
- Preserves sniffed charset parameters during refinement.
- Adds coverage for text, binary, and ZIP detection.
| File | Description |
|---|---|
metadata/mime.go |
Adds extension-aware MIME refinement. |
metadata/mime_test.go |
Tests Markdown and archive refinement behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- A zip archive isn't refined to an OpenDocument flat XML type, such as .fodt, as it's XML rather than a zip archive Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The document extensions are removed from the package's table, so the types of extensions are those registered by the caller, with mime.AddExtensionType, or the system's - Plain text is refined by an application type which is text, such as application/json, or a registered type, but not by a binary type, such as an image, application/octet-stream, or a zip archive Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Updates for content type detection, especially for text/* and application/zip types.
ContentTypesniffs the content first. When the sniffed type is generic, the file extension's type is used instead, if it's more specific:Plain text (
text/plain) is refined by:text/markdownfor.md;application/json, or a registered type such asapplication/vnd.google-apps.document.It's never refined by a binary type: an image, audio, video or font type,
application/octet-stream, or a ZIP archive.A ZIP archive (
application/zip) is refined by a document type that is a ZIP archive, such as Office Open XML, OpenDocument, or a type ending in+zip. OpenDocument's flat XML types (-flat-xml) are excluded, because those files are XML.Parameters: the sniffed parameters, such as the charset, are kept.
The extension types come from
mime.AddExtensionTypeor the system's types, so the caller registers the document types it handles. The package's own table keeps only its media extensions.🤖 Generated with Claude Code