From 9f10be5629557cfa40a5dd1d4050709d82967cdd Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Fri, 6 Dec 2024 09:36:26 -0800 Subject: [PATCH] add more extensions to mimetype database. (#1417) fallback to text/plain for 0 byte files --- pkg/util/utilfn/mimetypes.go | 6 ++++++ pkg/util/utilfn/utilfn.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/pkg/util/utilfn/mimetypes.go b/pkg/util/utilfn/mimetypes.go index 1e464ac29..fdd601d43 100644 --- a/pkg/util/utilfn/mimetypes.go +++ b/pkg/util/utilfn/mimetypes.go @@ -572,6 +572,8 @@ var StaticMimeTypeMap = map[string]string{ ".oeb": "application/vnd.openeye.oeb", ".oxt": "application/vnd.openofficeorg.extension", ".osm": "application/vnd.openstreetmap.data+xml", + ".exe": "application/vnd.microsoft.portable-executable", + ".dll": "application/vnd.microsoft.portable-executable", ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation", ".sldx": "application/vnd.openxmlformats-officedocument.presentationml.slide", ".ppsx": "application/vnd.openxmlformats-officedocument.presentationml.slideshow", @@ -1108,14 +1110,18 @@ var StaticMimeTypeMap = map[string]string{ ".jsx": "text/jsx", ".less": "text/less", ".md": "text/markdown", + ".mdx": "text/mdx", ".m": "text/mips", ".miz": "text/mizar", ".n3": "text/n3", ".txt": "text/plain", + ".conf": "text/plain", + ".awk": "text/x-awk", ".provn": "text/provenance-notation", ".rst": "text/prs.fallenstein.rst", ".tag": "text/prs.lines.tag", ".rs": "text/x-rust", + ".ini": "text/x-ini", ".sass": "text/scss", ".scss": "text/scss", ".sgml": "text/SGML", diff --git a/pkg/util/utilfn/utilfn.go b/pkg/util/utilfn/utilfn.go index 84b7e7921..626d9730b 100644 --- a/pkg/util/utilfn/utilfn.go +++ b/pkg/util/utilfn/utilfn.go @@ -620,6 +620,7 @@ func CopyToChannel(outputCh chan<- []byte, reader io.Reader) error { // on error just returns "" // does not return "application/octet-stream" as this is considered a detection failure // can pass an existing fileInfo to avoid re-statting the file +// falls back to text/plain for 0 byte files func DetectMimeType(path string, fileInfo fs.FileInfo, extended bool) string { if fileInfo == nil { statRtn, err := os.Stat(path) @@ -648,6 +649,9 @@ func DetectMimeType(path string, fileInfo fs.FileInfo, extended bool) string { if mimeType := mime.TypeByExtension(ext); mimeType != "" { return mimeType } + if fileInfo.Size() == 0 { + return "text/plain" + } if !extended { return "" }