diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-04-20 12:05:25 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-04-20 12:51:11 +0200 |
commit | e73f7a770dfb06f23d842d589bdd3d0fb53c7eed (patch) | |
tree | af6d08afa2fd16f1d30c2ab66de9c16b46931e2a /media/mediaType_test.go | |
parent | 3ddffd064dbacf62aa854b26ea8ddc5d15ba1ef8 (diff) |
Regression in media type suffix lookup
Introduced in Hugo 0.82.0.
Fixes #8406
Diffstat (limited to 'media/mediaType_test.go')
-rw-r--r-- | media/mediaType_test.go | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/media/mediaType_test.go b/media/mediaType_test.go index 6bc42b3d4..8d92ed1b2 100644 --- a/media/mediaType_test.go +++ b/media/mediaType_test.go @@ -15,6 +15,7 @@ package media import ( "encoding/json" + "sort" "testing" qt "github.com/frankban/quicktest" @@ -98,11 +99,28 @@ func TestBySuffix(t *testing.T) { func TestGetFirstBySuffix(t *testing.T) { c := qt.New(t) - _, f, found := DefaultTypes.GetFirstBySuffix("xml") - c.Assert(found, qt.Equals, true) - c.Assert(f, qt.Equals, SuffixInfo{ - Suffix: "xml", - FullSuffix: ".xml"}) + + types := DefaultTypes + + // Issue #8406 + geoJSON := newMediaTypeWithMimeSuffix("application", "geo", "json", []string{"geojson", "gjson"}) + types = append(types, geoJSON) + sort.Sort(types) + + check := func(suffix string, expectedType Type) { + t, f, found := types.GetFirstBySuffix(suffix) + c.Assert(found, qt.Equals, true) + c.Assert(f, qt.Equals, SuffixInfo{ + Suffix: suffix, + FullSuffix: "." + suffix}) + c.Assert(t, qt.Equals, expectedType) + } + + check("js", JavascriptType) + check("json", JSONType) + check("geojson", geoJSON) + check("gjson", geoJSON) + } func TestFromTypeString(t *testing.T) { |