1
0
mirror of https://github.com/golang/go synced 2024-11-24 09:50:17 -07:00

mime: ignore non-extension globs2 entries

Change-Id: Ic2315b593dca5648c02f793b7650b5936a997bff
GitHub-Last-Rev: ee55edcf08
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>
This commit is contained in:
Ville Skyttä 2022-02-16 21:00:04 +00:00 committed by Ian Lance Taylor
parent ac01de5446
commit df2421de60
3 changed files with 7 additions and 3 deletions

View File

@ -6,4 +6,6 @@
# mime package test for globs2 # mime package test for globs2
50:document/test:*.t3 50:document/test:*.t3
50:example/test:*.t4 50:example/test:*.t4
50:text/plain:*,v
50:application/x-trash:*~
30:example/do-not-use:*.t4 30:example/do-not-use:*.t4

View File

@ -40,11 +40,11 @@ func loadMimeGlobsFile(filename string) error {
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
for scanner.Scan() { 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(), ":") 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 continue
} else if fields[0][0] == '#' || fields[2][0] != '*' { } else if fields[0][0] == '#' || fields[2][0] != '*' || fields[2][1] != '.' {
continue continue
} }

View File

@ -27,6 +27,8 @@ func TestTypeByExtensionUNIX(t *testing.T) {
".t3": "document/test", ".t3": "document/test",
".t4": "example/test", ".t4": "example/test",
".png": "image/png", ".png": "image/png",
",v": "",
"~": "",
} }
for ext, want := range typeTests { for ext, want := range typeTests {