fix: paramaters of type character and bit not ignoring length

- Fixes the error "value too long for type character(1)" when the char length of the parameter was bigger than one.
This commit is contained in:
Laurence Isla
2023-07-31 18:36:37 -05:00
committed by GitHub
parent 0dc67bed0b
commit 40c2bcd4a1
8 changed files with 72 additions and 16 deletions
+22
View File
@@ -1447,3 +1447,25 @@ spec actualPgVersion =
{ matchStatus = 400
, matchHeaders = [matchContentTypeJson]
}
-- https://github.com/PostgREST/postgrest/issues/1586#issuecomment-696345442
context "a proc with bit and char parameters" $ do
it "modifies the param type from character to character varying" $ do
get "/rpc/char_param_select?char_=abcdefg&char_arr={abc,abcdefg}" `shouldRespondWith`
[json| [{ "char_": "abcdefg", "char_arr": [ "abc", "abcdefg" ] }] |]
{ matchHeaders = [matchContentTypeJson] }
post "/rpc/char_param_insert" [json| { "char_": "abcdefg", "char_arr": "{abc,abcdefg}" } |]
`shouldRespondWith`
[json| {"code":"22001","details":null,"hint":null,"message":"value too long for type character(5)"} |]
{ matchStatus = 400 }
it "modifies the param type from bit to bit varying" $ do
get "/rpc/bit_param_select?bit_=101010&bit_arr={101,101010}" `shouldRespondWith`
[json| [{ "bit_": "101010", "bit_arr": [ "101", "101010" ] }] |]
{ matchHeaders = [matchContentTypeJson] }
post "/rpc/bit_param_insert" [json| { "bit_": "101010", "bit_arr": "{101,101010}" } |]
`shouldRespondWith`
[json| {"code":"22026","details":null,"hint":null,"message":"bit string length 6 does not match type bit(5)"} |]
{ matchStatus = 400 }
+2 -2
View File
@@ -387,14 +387,14 @@ spec actualPgVersion = do
-- https://github.com/PostgREST/postgrest/issues/2861
context "bit and char columns with length" $ do
it "should update a bit column with length" $
request methodPatch "/bitchar_with_length?char=eq.aaaaa"
request methodPatch "/bitchar_with_length?select=bit,char&char=eq.aaaaa"
[("Prefer", "return=representation")]
[json|{"bit": "11100"}|]
`shouldRespondWith` [json|[{ "bit": "11100", "char": "aaaaa" }]|]
{ matchStatus = 200 }
it "should update a char column with length" $
request methodPatch "/bitchar_with_length?bit=eq.00000"
request methodPatch "/bitchar_with_length?select=bit,char&bit=eq.00000"
[("Prefer", "return=representation")]
[json|{"char": "zzzyy"}|]
`shouldRespondWith` [json|[{ "bit": "00000", "char": "zzzyy" }]|]