mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
@@ -117,7 +117,7 @@ func FromContent(types Types, extensionHints []string, content []byte) Type {
|
||||
|
||||
// FromStringAndExt creates a Type from a MIME string and a given extension.
|
||||
func FromStringAndExt(t, ext string) (Type, error) {
|
||||
tp, err := fromString(t)
|
||||
tp, err := FromString(t)
|
||||
if err != nil {
|
||||
return tp, err
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func FromStringAndExt(t, ext string) (Type, error) {
|
||||
|
||||
// FromString creates a new Type given a type string on the form MainType/SubType and
|
||||
// an optional suffix, e.g. "text/html" or "text/html+html".
|
||||
func fromString(t string) (Type, error) {
|
||||
func FromString(t string) (Type, error) {
|
||||
t = strings.ToLower(t)
|
||||
parts := strings.Split(t, "/")
|
||||
if len(parts) != 2 {
|
||||
@@ -470,7 +470,7 @@ func DecodeTypes(mms ...map[string]any) (Types, error) {
|
||||
mediaType, found := mmm[k]
|
||||
if !found {
|
||||
var err error
|
||||
mediaType, err = fromString(k)
|
||||
mediaType, err = FromString(k)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
|
@@ -132,22 +132,22 @@ func TestGetFirstBySuffix(t *testing.T) {
|
||||
|
||||
func TestFromTypeString(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
f, err := fromString("text/html")
|
||||
f, err := FromString("text/html")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(f.Type(), qt.Equals, HTMLType.Type())
|
||||
|
||||
f, err = fromString("application/custom")
|
||||
f, err = FromString("application/custom")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(f, qt.Equals, Type{MainType: "application", SubType: "custom", mimeSuffix: ""})
|
||||
|
||||
f, err = fromString("application/custom+sfx")
|
||||
f, err = FromString("application/custom+sfx")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(f, qt.Equals, Type{MainType: "application", SubType: "custom", mimeSuffix: "sfx"})
|
||||
|
||||
_, err = fromString("noslash")
|
||||
_, err = FromString("noslash")
|
||||
c.Assert(err, qt.Not(qt.IsNil))
|
||||
|
||||
f, err = fromString("text/xml; charset=utf-8")
|
||||
f, err = FromString("text/xml; charset=utf-8")
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
c.Assert(f, qt.Equals, Type{MainType: "text", SubType: "xml", mimeSuffix: ""})
|
||||
|
Reference in New Issue
Block a user