diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/federation/federatingactor.go | 17 | ||||
-rw-r--r-- | internal/federation/federatingactor_test.go | 20 |
2 files changed, 31 insertions, 6 deletions
diff --git a/internal/federation/federatingactor.go b/internal/federation/federatingactor.go index 8fc47462d..b91165bb1 100644 --- a/internal/federation/federatingactor.go +++ b/internal/federation/federatingactor.go @@ -40,7 +40,7 @@ import ( // - application/activity+json // - application/ld+json;profile=https://w3.org/ns/activitystreams // -// Where for the above we are leniant with whitespace and quotes. +// Where for the above we are leniant with whitespace, quotes, and charset. func IsASMediaType(ct string) bool { var ( // First content-type part, @@ -48,7 +48,8 @@ func IsASMediaType(ct string) bool { p1 string = ct //nolint:revive // Second content-type part, - // contains AS IRI if provided + // contains AS IRI or charset + // if provided. p2 string ) @@ -56,7 +57,11 @@ func IsASMediaType(ct string) bool { sep := strings.IndexByte(ct, ';') if sep >= 0 { p1 = ct[:sep] + + // Trim all start/end + // space of second part. p2 = ct[sep+1:] + p2 = strings.Trim(p2, " ") } // Trim any ending space from the @@ -65,12 +70,12 @@ func IsASMediaType(ct string) bool { switch p1 { case "application/activity+json": - return p2 == "" + // Accept with or without charset. + // This should be case insensitive. + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type#charset + return p2 == "" || strings.EqualFold(p2, "charset=utf-8") case "application/ld+json": - // Trim all start/end space. - p2 = strings.Trim(p2, " ") - // Drop any quotes around the URI str. p2 = strings.ReplaceAll(p2, "\"", "") diff --git a/internal/federation/federatingactor_test.go b/internal/federation/federatingactor_test.go index 348d501d6..d07b56537 100644 --- a/internal/federation/federatingactor_test.go +++ b/internal/federation/federatingactor_test.go @@ -165,6 +165,22 @@ func TestIsASMediaType(t *testing.T) { Expect: true, }, { + Input: "application/activity+json; charset=utf-8", + Expect: true, + }, + { + Input: "application/activity+json;charset=utf-8", + Expect: true, + }, + { + Input: "application/activity+json ;charset=utf-8", + Expect: true, + }, + { + Input: "application/activity+json ; charset=utf-8", + Expect: true, + }, + { Input: "application/ld+json;profile=https://www.w3.org/ns/activitystreams", Expect: true, }, @@ -196,6 +212,10 @@ func TestIsASMediaType(t *testing.T) { Input: "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", Expect: true, }, + { + Input: "application/ld+json", + Expect: false, + }, } { if federation.IsASMediaType(test.Input) != test.Expect { t.Errorf("did not get expected result %v for input: %s", test.Expect, test.Input) |