Skip to content

mime: ExtensionsByType is non-deterministic for image/jpeg #39283

Closed
@chowey

Description

@chowey

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

$ go version
go version go1.14.3 darwin/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}/Library/Caches/go-build"
GOENV="${HOME}/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY="${PRIVATE_REPO}"
GONOSUMDB="${PRIVATE_REPO}"
GOOS="darwin"
GOPATH="${HOME}/go"
GOPRIVATE="${PRIVATE_REPO}"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8p/p5rdrmpd5n1gwqv8c6dxb0hc0000gn/T/go-build696615722=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I ran the following code:

https://play.golang.org/p/oVTZQTyxzS_q

The relevant bit is here:

exts, _ := mime.ExtensionsByType("image/jpeg")

What did you expect to see?

I expected to see a consistent result. One of the following would have worked, so long as it were deterministic:

  • [.jpg]
  • [.jpeg]
  • [.jpg .jpeg]
  • [.jpeg .jpg]

What did you see instead?

I saw either [.jpg] or [.jpeg], which changed as I re-ran the program.

Perhaps these extensions are completely interchangeable, but I think they should be deterministic. This affects e.g. unit tests which rely on ExtensionsByType somewhere in the code path.

(Personally, I prefer .jpg over .jpeg.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions