Skip to content

Commit e73f7a7

Browse files
committed
Regression in media type suffix lookup
Introduced in Hugo 0.82.0. Fixes #8406
1 parent 3ddffd0 commit e73f7a7

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

media/mediaType.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func (t Types) GetBySuffix(suffix string) (tp Type, si SuffixInfo, found bool) {
305305
}
306306

307307
func (m Type) hasSuffix(suffix string) bool {
308-
return strings.Contains(m.suffixesCSV, suffix)
308+
return strings.Contains(","+m.suffixesCSV+",", ","+suffix+",")
309309
}
310310

311311
// GetByMainSubType gets a media type given a main and a sub type e.g. "text" and "plain".

media/mediaType_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package media
1515

1616
import (
1717
"encoding/json"
18+
"sort"
1819
"testing"
1920

2021
qt "github.com/frankban/quicktest"
@@ -98,11 +99,28 @@ func TestBySuffix(t *testing.T) {
9899

99100
func TestGetFirstBySuffix(t *testing.T) {
100101
c := qt.New(t)
101-
_, f, found := DefaultTypes.GetFirstBySuffix("xml")
102-
c.Assert(found, qt.Equals, true)
103-
c.Assert(f, qt.Equals, SuffixInfo{
104-
Suffix: "xml",
105-
FullSuffix: ".xml"})
102+
103+
types := DefaultTypes
104+
105+
// Issue #8406
106+
geoJSON := newMediaTypeWithMimeSuffix("application", "geo", "json", []string{"geojson", "gjson"})
107+
types = append(types, geoJSON)
108+
sort.Sort(types)
109+
110+
check := func(suffix string, expectedType Type) {
111+
t, f, found := types.GetFirstBySuffix(suffix)
112+
c.Assert(found, qt.Equals, true)
113+
c.Assert(f, qt.Equals, SuffixInfo{
114+
Suffix: suffix,
115+
FullSuffix: "." + suffix})
116+
c.Assert(t, qt.Equals, expectedType)
117+
}
118+
119+
check("js", JavascriptType)
120+
check("json", JSONType)
121+
check("geojson", geoJSON)
122+
check("gjson", geoJSON)
123+
106124
}
107125

108126
func TestFromTypeString(t *testing.T) {

0 commit comments

Comments
 (0)