]> Cypherpunks repositories - gostls13.git/commitdiff
mime: ignore non-extension globs2 entries
authorVille Skyttä <ville.skytta@iki.fi>
Wed, 16 Feb 2022 21:00:04 +0000 (21:00 +0000)
committerIan Lance Taylor <iant@golang.org>
Fri, 15 Apr 2022 17:07:27 +0000 (17:07 +0000)
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>
src/mime/testdata/test.types.globs2
src/mime/type_unix.go
src/mime/type_unix_test.go

index cb5b7899b0d5f5d7385ebd974cf6a76d1656d436..fd9df7078bd877d02ed00629a9f882ac461f795c 100644 (file)
@@ -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
index 52579c56b9acb62b715017e929ea1d84e5d6a863..e297ecf5c1aa78f6d8dc9f441daeeb90dfbf403e 100644 (file)
@@ -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
                }
 
index 6bb408566cd1abb3e373e4d40ff830b714ead77a..ab14ae6f80cc42b2b8f4e1cd62ead94054f6d53e 100644 (file)
@@ -27,6 +27,8 @@ func TestTypeByExtensionUNIX(t *testing.T) {
                ".t3":  "document/test",
                ".t4":  "example/test",
                ".png": "image/png",
+               ",v":   "",
+               "~":    "",
        }
 
        for ext, want := range typeTests {