From feb5b7d49403abb93a0d02a72cf0b6e0f189f503 Mon Sep 17 00:00:00 2001 From: Taimoor Zaeem Date: Mon, 14 Apr 2025 19:57:54 +0500 Subject: [PATCH] fix: regression that replaces an unknown media type with */* (#4013) --- src/PostgREST/MediaType.hs | 2 +- test/spec/Feature/Query/CustomMediaSpec.hs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/PostgREST/MediaType.hs b/src/PostgREST/MediaType.hs index ca815f7f3..ba79c3a51 100644 --- a/src/PostgREST/MediaType.hs +++ b/src/PostgREST/MediaType.hs @@ -155,7 +155,7 @@ decodeMediaType mt = decodeMediaType' $ decodeLatin1 mt mediaTypeOrError = P.parse tokenizeMediaType "parsec: tokenizeMediaType failed" $ T.unpack mt' (mainType, subType, params') = case mediaTypeOrError of Right mt'' -> mt'' - Left _ -> ("*", "*", []) -- TODO: Throw mediatype error, would need refactoring because currently Error module depend on MediaType module + Left _ -> (mt',"",[]) params = fromList $ map (first T.toLower) params' -- normalize parameter names to lowercase, per RFC 7321 getPlan fmt = MTVndPlan mtFor fmt $ [PlanAnalyze | inOpts "analyze" ] ++ diff --git a/test/spec/Feature/Query/CustomMediaSpec.hs b/test/spec/Feature/Query/CustomMediaSpec.hs index 1b1773861..219047f28 100644 --- a/test/spec/Feature/Query/CustomMediaSpec.hs +++ b/test/spec/Feature/Query/CustomMediaSpec.hs @@ -375,3 +375,10 @@ spec = describe "custom media types" $ do { matchStatus = 200 , matchHeaders = ["Content-Type" <:> "application/octet-stream"] } + + context "media type parser fails" $ do + it "sends media type as is" $ + request methodGet "/items" (acceptHdrs "undefined") "" + `shouldRespondWith` + [json| {"code":"PGRST107","details":null,"hint":null,"message":"None of these media types are available: undefined"} |] + { matchStatus = 406 }