Skip to content

mime: mime.ExtensionsByType returns an unexpected extension ",v" for "text/plain" #52065

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

Closed
PetitCassoulet opened this issue Mar 31, 2022 · 2 comments

Comments

@PetitCassoulet
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/me/.cache/go-build"
GOENV="/home/me/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/me/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/me/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/me/project/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build697837538=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"fmt"
	"mime"
)

func main() {
	val, err := mime.ExtensionsByType("text/plain")
	if err != nil {
		panic(err)
	}

	fmt.Printf("%+v", val)
}

What did you expect to see?

Definitely not ,v as a valid extension

What did you see instead?

[,v .asc .inf .ini .txt]

@jimen0
Copy link
Contributor

jimen0 commented Mar 31, 2022

Hi @PetitCassoulet - Per the docs, on Linux following files are checked for the mime types database:

var mimeGlobs = []string{
	"/usr/local/share/mime/globs2",
	"/usr/share/mime/globs2",
}

var typeFiles = []string{
	"/etc/mime.types",
	"/etc/apache2/mime.types",
	"/etc/apache/mime.types",
	"/etc/httpd/conf/mime.types",
}

Source: https://cs.opensource.google/go/go/+/refs/tags/go1.18:src/mime/type_unix.go;l=19-32

Maybe one of these is corrupted in your system? I get the correct output both with 1.17 and current tip on a macos system.

Thanks!


EDIT: reproduced on an Ubuntu container. Go got the ,v from /usr/share/mime/globs2:

# cat /usr/share/mime/globs2 | grep ",v"
50:text/plain:*,v

Container version:

# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"

@seankhliao
Copy link
Member

As noted above, mime types are provided by the underlying system, and it looks like this was an intentional addition by OS maintainers: https://unix.stackexchange.com/questions/666614/reason-for-text-plain-pattern-v-in-shared-mime-info

Closing as there's nothing to do in Go.

@golang golang locked and limited conversation to collaborators Mar 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants