aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2022-02-16 21:00:04 +0000
committerIan Lance Taylor <iant@golang.org>2022-04-15 17:07:27 +0000
commitdf2421de60215cfc314fe6772ff6c2c6201f7abb (patch)
treeebd94d2cbfd480620f9ef66b504e36ddd09c18d9 /src
parentac01de5446ec92544768dabee3b0d1faf5f596d9 (diff)
downloadgo-df2421de60215cfc314fe6772ff6c2c6201f7abb.tar.xz
mime: ignore non-extension globs2 entries
Change-Id: Ic2315b593dca5648c02f793b7650b5936a997bff GitHub-Last-Rev: ee55edcf087416c6f0d50d5dd51cbddfd1d77620 GitHub-Pull-Request: golang/go#51226 Reviewed-on: https://go-review.googlesource.com/c/go/+/386334 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/mime/testdata/test.types.globs22
-rw-r--r--src/mime/type_unix.go6
-rw-r--r--src/mime/type_unix_test.go2
3 files changed, 7 insertions, 3 deletions
diff --git a/src/mime/testdata/test.types.globs2 b/src/mime/testdata/test.types.globs2
index cb5b7899b0..fd9df7078b 100644
--- a/src/mime/testdata/test.types.globs2
+++ b/src/mime/testdata/test.types.globs2
@@ -6,4 +6,6 @@
# mime package test for globs2
50:document/test:*.t3
50:example/test:*.t4
+50:text/plain:*,v
+50:application/x-trash:*~
30:example/do-not-use:*.t4
diff --git a/src/mime/type_unix.go b/src/mime/type_unix.go
index 52579c56b9..e297ecf5c1 100644
--- a/src/mime/type_unix.go
+++ b/src/mime/type_unix.go
@@ -40,11 +40,11 @@ func loadMimeGlobsFile(filename string) error {
scanner := bufio.NewScanner(f)
for scanner.Scan() {
- // Each line should be of format: weight:mimetype:*.ext
+ // Each line should be of format: weight:mimetype:*.ext[:morefields...]
fields := strings.Split(scanner.Text(), ":")
- if len(fields) < 3 || len(fields[0]) < 1 || len(fields[2]) < 2 {
+ if len(fields) < 3 || len(fields[0]) < 1 || len(fields[2]) < 3 {
continue
- } else if fields[0][0] == '#' || fields[2][0] != '*' {
+ } else if fields[0][0] == '#' || fields[2][0] != '*' || fields[2][1] != '.' {
continue
}
diff --git a/src/mime/type_unix_test.go b/src/mime/type_unix_test.go
index 6bb408566c..ab14ae6f80 100644
--- a/src/mime/type_unix_test.go
+++ b/src/mime/type_unix_test.go
@@ -27,6 +27,8 @@ func TestTypeByExtensionUNIX(t *testing.T) {
".t3": "document/test",
".t4": "example/test",
".png": "image/png",
+ ",v": "",
+ "~": "",
}
for ext, want := range typeTests {