]> Cypherpunks repositories - gostls13.git/commitdiff
mime: in globs2 file only keep first time extension is seen
authorIan Lance Taylor <iant@golang.org>
Tue, 13 Apr 2021 05:26:37 +0000 (22:26 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 13 Apr 2021 18:08:06 +0000 (18:08 +0000)
Fixes #45534

Change-Id: I9855607e845951f26ab85cb179ec6dea40d92156
Reviewed-on: https://go-review.googlesource.com/c/go/+/309574
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/mime/testdata/test.types.globs2
src/mime/type_unix.go

index 2e893262ea1eed28930bc69940b7b928f9144a5e..cb5b7899b0d5f5d7385ebd974cf6a76d1656d436 100644 (file)
@@ -6,3 +6,4 @@
 # mime package test for globs2
 50:document/test:*.t3
 50:example/test:*.t4
+30:example/do-not-use:*.t4
index 59c99e2c86c37132b1b4d718a6ad73e0f2fb6448..f954bc8a1fba6811ef0daff83c3ab2ecada9aa2a 100644 (file)
@@ -49,7 +49,15 @@ func loadMimeGlobsFile(filename string) error {
                        continue
                }
 
-               setExtensionType(fields[2][1:], fields[1])
+               extension := fields[2][1:]
+               if _, ok := mimeTypes.Load(extension); ok {
+                       // We've already seen this extension.
+                       // The file is in weight order, so we keep
+                       // the first entry that we see.
+                       continue
+               }
+
+               setExtensionType(extension, fields[1])
        }
        if err := scanner.Err(); err != nil {
                panic(err)