Fix - ParseVendorSpecificContentType fir dart content type (#1594)

Close #1582
pull/1597/head
RW 2021-10-25 07:13:57 +02:00 committed by GitHub
parent 36796ee7a1
commit 658b4e42b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -37,8 +37,10 @@ func ParseVendorSpecificContentType(cType string) string {
var parsableType string
if semiColonIndex := strings.Index(cType, ";"); semiColonIndex == -1 {
parsableType = cType[plusIndex+1:]
} else {
} else if plusIndex < semiColonIndex {
parsableType = cType[plusIndex+1 : semiColonIndex]
} else {
return cType[:semiColonIndex]
}
slashIndex := strings.Index(cType, "/")

View File

@ -59,6 +59,12 @@ func Test_ParseVendorSpecificContentType(t *testing.T) {
cType := ParseVendorSpecificContentType("application/json")
AssertEqual(t, "application/json", cType)
cType = ParseVendorSpecificContentType("multipart/form-data; boundary=dart-http-boundary-ZnVy.ICWq+7HOdsHqWxCFa8g3D.KAhy+Y0sYJ_lBADypu8po3_X")
AssertEqual(t, "multipart/form-data", cType)
cType = ParseVendorSpecificContentType("multipart/form-data")
AssertEqual(t, "multipart/form-data", cType)
cType = ParseVendorSpecificContentType("application/vnd.api+json; version=1")
AssertEqual(t, "application/json", cType)