diff --git a/src/PostgREST/Request/ApiRequest.hs b/src/PostgREST/Request/ApiRequest.hs index 7fcbf60b9..e67b5689d 100644 --- a/src/PostgREST/Request/ApiRequest.hs +++ b/src/PostgREST/Request/ApiRequest.hs @@ -243,9 +243,9 @@ userApiRequest conf@AppConfig{..} dbStructure req reqBody parsedColumns = pRequestColumns columns payloadColumns = case (contentType, action) of - (_, ActionInvoke InvGet) -> S.fromList $ fst <$> rpcQParams - (_, ActionInvoke InvHead) -> S.fromList $ fst <$> rpcQParams - (CTOther "application/x-www-form-urlencoded", _) -> S.fromList $ map (toS . fst) $ parseSimpleQuery $ toS reqBody + (_, ActionInvoke InvGet) -> S.fromList $ fst <$> rpcQParams + (_, ActionInvoke InvHead) -> S.fromList $ fst <$> rpcQParams + (CTUrlEncoded, _) -> S.fromList $ map (toS . fst) $ parseSimpleQuery $ toS reqBody _ -> case (relevantPayload, fromRight Nothing parsedColumns) of (Just ProcessedJSON{pjKeys}, _) -> pjKeys (Just RawJSON{}, Just cls) -> cls diff --git a/test/Feature/RpcSpec.hs b/test/Feature/RpcSpec.hs index 893559c86..6b9481401 100644 --- a/test/Feature/RpcSpec.hs +++ b/test/Feature/RpcSpec.hs @@ -659,6 +659,34 @@ spec actualPgVersion = it "overloaded(text, text, text)" $ get "/rpc/overloaded?a=1&b=2&c=3" `shouldRespondWith` [json|"123"|] + it "overloaded_html_form()" $ + request methodPost "/rpc/overloaded_html_form" + [("Content-Type", "application/x-www-form-urlencoded")] + "" + `shouldRespondWith` + [json|[1,2,3]|] + + it "overloaded_html_form(json) single-object" $ + request methodPost "/rpc/overloaded_html_form" + [("Content-Type", "application/x-www-form-urlencoded"), ("Prefer","params=single-object")] + "a=1&b=2&c=3" + `shouldRespondWith` + [json|{"a": "1", "b": "2", "c": "3"}|] + + it "overloaded_html_form(int, int)" $ + request methodPost "/rpc/overloaded_html_form" + [("Content-Type", "application/x-www-form-urlencoded")] + "a=1&b=2" + `shouldRespondWith` + [str|3|] + + it "overloaded_html_form(text, text, text)" $ + request methodPost "/rpc/overloaded_html_form" + [("Content-Type", "application/x-www-form-urlencoded")] + "a=1&b=2&c=3" + `shouldRespondWith` + [json|"123"|] + context "only for POST rpc" $ do it "gives a parse filter error if GET style proc args are specified" $ post "/rpc/sayhello?name=John" [json|{}|] `shouldRespondWith` 400 diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index 6099cbf74..0d4ca85d4 100644 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -1267,6 +1267,22 @@ create or replace function test.overloaded(a text, b text, c text) returns text select a || b || c $$ language sql; +create or replace function test.overloaded_html_form() returns setof int as $$ +values (1), (2), (3); +$$ language sql; + +create or replace function test.overloaded_html_form(single_param json) returns json as $$ +select single_param; +$$ language sql; + +create or replace function test.overloaded_html_form(a int, b int) returns int as $$ +select a + b +$$ language sql; + +create or replace function test.overloaded_html_form(a text, b text, c text) returns text as $$ +select a || b || c +$$ language sql; + create table test.leak( id serial primary key, blob bytea