Skip to content

Commit

Permalink
Fixed registration of custom extensions in the mime registry (cs3org#…
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern authored Nov 8, 2023
1 parent da71403 commit 84558ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit 84558ba

Please sign in to comment.