From 4b4a622a1702f29c394f12ad25349956abade878 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Wed, 28 Oct 2020 19:03:36 +0100 Subject: [PATCH] fix non-variadic repeated param in variadic function --- src/PostgREST/ApiRequest.hs | 2 +- test/Feature/RpcSpec.hs | 6 ++++++ test/fixtures/schema.sql | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/PostgREST/ApiRequest.hs b/src/PostgREST/ApiRequest.hs index f82606f2d..b6b4656ee 100644 --- a/src/PostgREST/ApiRequest.hs +++ b/src/PostgREST/ApiRequest.hs @@ -94,7 +94,7 @@ jsonRpcParams proc prms = where mergeParams :: RpcParamValue -> RpcParamValue -> RpcParamValue mergeParams (Variadic a) (Variadic b) = Variadic $ b ++ a - mergeParams _ v = v -- repeated params for non-variadic arguments are not merged + mergeParams v _ = v -- repeated params for non-variadic arguments are not merged {-| Describes what the user wants to do. This data type is a diff --git a/test/Feature/RpcSpec.hs b/test/Feature/RpcSpec.hs index b894fab1c..05863f01d 100644 --- a/test/Feature/RpcSpec.hs +++ b/test/Feature/RpcSpec.hs @@ -528,6 +528,12 @@ spec actualPgVersion = `shouldRespondWith` [json|"Hello, world"|] + when (actualPgVersion >= pgVersion100) $ + it "returns last value for repeated non-variadic params in function with other VARIADIC arguments" $ + get "/rpc/sayhello_variadic?name=ignored&name=world&v=unused" + `shouldRespondWith` + [json|"Hello, world"|] + it "can handle procs with args that have a DEFAULT value" $ do get "/rpc/many_inout_params?num=1&str=two" `shouldRespondWith` [json| [{"num":1,"str":"two","b":true}]|] { matchHeaders = [matchContentTypeJson] } diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index 9d848c930..efd0b7971 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -1084,9 +1084,14 @@ create function test.many_inout_params(INOUT num int, INOUT str text, INOUT b bo $$ language sql; CREATE FUNCTION test.variadic_param(VARIADIC v TEXT[] DEFAULT '{}') RETURNS text[] -LANGUAGE SQL AS $_$ +LANGUAGE SQL AS $$ SELECT v -$_$; +$$; + +CREATE FUNCTION test.sayhello_variadic(name TEXT, VARIADIC v TEXT[]) RETURNS text +LANGUAGE SQL AS $$ + SELECT 'Hello, ' || name +$$; create or replace function test.raise_pt402() returns void as $$ begin