File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package mime
7
7
8
8
import (
9
9
"fmt"
10
+ "sort"
10
11
"strings"
11
12
"sync"
12
13
)
@@ -49,7 +50,7 @@ func setMimeTypes(lowerExt, mixExt map[string]string) {
49
50
panic (err )
50
51
}
51
52
var exts []string
52
- if ei , ok := extensions .Load (k ); ok {
53
+ if ei , ok := extensions .Load (justType ); ok {
53
54
exts = ei .([]string )
54
55
}
55
56
extensions .Store (justType , append (exts , k ))
@@ -151,7 +152,9 @@ func ExtensionsByType(typ string) ([]string, error) {
151
152
if ! ok {
152
153
return nil , nil
153
154
}
154
- return append ([]string {}, s .([]string )... ), nil
155
+ ret := append ([]string (nil ), s .([]string )... )
156
+ sort .Strings (ret )
157
+ return ret , nil
155
158
}
156
159
157
160
// AddExtensionType sets the MIME type associated with
Original file line number Diff line number Diff line change @@ -188,3 +188,30 @@ func BenchmarkExtensionsByType(b *testing.B) {
188
188
})
189
189
}
190
190
}
191
+
192
+ func TestExtensionsByType2 (t * testing.T ) {
193
+ cleanup := setMimeInit (func () {
194
+ clearMimeTypes ()
195
+ // Initialize built-in types like in type.go before osInitMime.
196
+ setMimeTypes (builtinTypesLower , builtinTypesLower )
197
+ })
198
+ defer cleanup ()
199
+
200
+ tests := []struct {
201
+ typ string
202
+ want []string
203
+ }{
204
+ {typ : "image/jpeg" , want : []string {".jpeg" , ".jpg" }},
205
+ }
206
+
207
+ for _ , tt := range tests {
208
+ got , err := ExtensionsByType (tt .typ )
209
+ if err != nil {
210
+ t .Errorf ("ExtensionsByType(%q): %v" , tt .typ , err )
211
+ continue
212
+ }
213
+ if ! reflect .DeepEqual (got , tt .want ) {
214
+ t .Errorf ("ExtensionsByType(%q) = %q; want %q" , tt .typ , got , tt .want )
215
+ }
216
+ }
217
+ }
You can’t perform that action at this time.
0 commit comments