From 36eb01404af5f0e3c60cf304edad9c4dd706d332 Mon Sep 17 00:00:00 2001 From: Andrei Dziahel Date: Mon, 4 Dec 2023 18:57:47 +0100 Subject: [PATCH 1/3] fix: replace json parser error with generic msg --- src/PostgREST/ApiRequest.hs | 4 +++- test/spec/Feature/Query/InsertSpec.hs | 4 ++-- test/spec/Feature/Query/UpdateSpec.hs | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/PostgREST/ApiRequest.hs b/src/PostgREST/ApiRequest.hs index 896aabbedb..52923583f2 100644 --- a/src/PostgREST/ApiRequest.hs +++ b/src/PostgREST/ApiRequest.hs @@ -259,7 +259,9 @@ getPayload reqBody contentMediaType QueryParams{qsColumns} action PathInfo{pathI else note "All object keys must match" . payloadAttributes reqBody =<< if LBS.null reqBody && pathIsProc then Right emptyObject - else first BS.pack $ JSON.eitherDecode reqBody + else first BS.pack $ + -- Drop parsing error message in favor of generic one (https://github.com/PostgREST/postgrest/issues/2344) + maybe (Left "Empty or invalid json") Right $ JSON.decode reqBody (MTTextCSV, _) -> do json <- csvToJson <$> first BS.pack (CSV.decodeByName reqBody) note "All lines must have same number of fields" $ payloadAttributes (JSON.encode json) json diff --git a/test/spec/Feature/Query/InsertSpec.hs b/test/spec/Feature/Query/InsertSpec.hs index 83695e1af1..817319912e 100644 --- a/test/spec/Feature/Query/InsertSpec.hs +++ b/test/spec/Feature/Query/InsertSpec.hs @@ -287,7 +287,7 @@ spec actualPgVersion = do it "fails with 400 and error" $ post "/simple_pk" "}{ x = 2" `shouldRespondWith` - [json|{"message":"Error in $: Failed reading: not a valid json value at '}{x=2'","code":"PGRST102","details":null,"hint":null}|] + [json|{"message":"Empty or invalid json","code":"PGRST102","details":null,"hint":null}|] { matchStatus = 400 , matchHeaders = [matchContentTypeJson] } @@ -296,7 +296,7 @@ spec actualPgVersion = do it "fails with 400 and error" $ post "/simple_pk" "" `shouldRespondWith` - [json|{"message":"Error in $: not enough input","code":"PGRST102","details":null,"hint":null}|] + [json|{"message":"Empty or invalid json","code":"PGRST102","details":null,"hint":null}|] { matchStatus = 400 , matchHeaders = [matchContentTypeJson] } diff --git a/test/spec/Feature/Query/UpdateSpec.hs b/test/spec/Feature/Query/UpdateSpec.hs index 362a00e326..7cf7013041 100644 --- a/test/spec/Feature/Query/UpdateSpec.hs +++ b/test/spec/Feature/Query/UpdateSpec.hs @@ -44,7 +44,7 @@ spec actualPgVersion = do it "fails with 400 and error" $ request methodPatch "/simple_pk" [] "}{ x = 2" `shouldRespondWith` - [json|{"message":"Error in $: Failed reading: not a valid json value at '}{x=2'","code":"PGRST102","details":null,"hint":null}|] + [json|{"message":"Empty or invalid json","code":"PGRST102","details":null,"hint":null}|] { matchStatus = 400, matchHeaders = [matchContentTypeJson] } @@ -53,7 +53,7 @@ spec actualPgVersion = do it "fails with 400 and error" $ request methodPatch "/items" [] "" `shouldRespondWith` - [json|{"message":"Error in $: not enough input","code":"PGRST102","details":null,"hint":null}|] + [json|{"message":"Empty or invalid json","code":"PGRST102","details":null,"hint":null}|] { matchStatus = 400, matchHeaders = [matchContentTypeJson] } From 28d81276d681179079abfb3f01f660f66f9ad003 Mon Sep 17 00:00:00 2001 From: Andrei Dziahel Date: Thu, 7 Dec 2023 22:29:09 +0100 Subject: [PATCH 2/3] changelog: add #3090 entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 746ed708a1..7e8614cf93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - #3054, Fix not allowing special characters in JSON keys - @laurenceisla + - #3090, Replace JSON parser error with generic message - @develop7 + + Fixes #2344 ## [12.0.0] - 2023-12-01 From 8e48b9de5feaf8f48548936a9f016172ebfe1d76 Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Thu, 7 Dec 2023 17:34:58 -0500 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e8614cf93..a638ec4ae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - #3054, Fix not allowing special characters in JSON keys - @laurenceisla - - #3090, Replace JSON parser error with generic message - @develop7 - + Fixes #2344 + - #2344, Replace JSON parser error with a clearer generic message - @develop7 ## [12.0.0] - 2023-12-01