Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed registration of custom extensions in the mime registry #4319

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/mimes-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: fixed registration of custom extensions in the mime registry

This PR ensures custom extensions/mime-types are registered by trimming
any eventual leading '.' from the extension.

https://github.com/cs3org/reva/pull/4319
6 changes: 2 additions & 4 deletions pkg/mime/mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func init() {
// a mime type with the given extension.
// TODO(labkode): check that we do not override mime type mappings?
func RegisterMime(ext, mime string) {
mimes.Store(ext, mime)
mimes.Store(strings.TrimPrefix(ext, "."), mime)
}

// Detect returns the mimetype associated with the given filename.
Expand All @@ -47,9 +47,7 @@ func Detect(isDir bool, fn string) string {
return defaultMimeDir
}

ext := path.Ext(fn)
ext = strings.TrimPrefix(ext, ".")

ext := strings.TrimPrefix(path.Ext(fn), ".")
mimeType := getCustomMime(ext)

if mimeType == "" {
Expand Down