From 9a596c25007fdba7eee86388d8347710367bd418 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Fri, 15 Jan 2016 00:37:38 +0200 Subject: [PATCH] pgFmtLit: Change condition for using E"..." syntax, fix #458. Includes a test spec by @diogob. --- src/PostgREST/QueryBuilder.hs | 2 +- test/Feature/InsertSpec.hs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/PostgREST/QueryBuilder.hs b/src/PostgREST/QueryBuilder.hs index aebcded84..52a2101d3 100644 --- a/src/PostgREST/QueryBuilder.hs +++ b/src/PostgREST/QueryBuilder.hs @@ -209,7 +209,7 @@ pgFmtLit x = let trimmed = trimNullChars x escaped = "'" <> replace "'" "''" trimmed <> "'" slashed = replace "\\" "\\\\" escaped in - if "\\\\" `isInfixOf` escaped + if "\\" `isInfixOf` escaped then "E" <> slashed else slashed diff --git a/test/Feature/InsertSpec.hs b/test/Feature/InsertSpec.hs index 4c4edc7ca..b1f8f0df5 100644 --- a/test/Feature/InsertSpec.hs +++ b/test/Feature/InsertSpec.hs @@ -367,6 +367,17 @@ spec struct pool = beforeAll_ resetDb $ around (withApp cfgDefault struct pool) [json| { id: 99 } |] `shouldRespondWith` [json| [{id:99}] |] + it "can set a json column to escaped value" $ do + _ <- post "/json" [json| { data: {"escaped":"bar"} } |] + request methodPatch "/json?data->>escaped=eq.bar" + [("Prefer", "return=representation")] + [json| { "data": { "escaped":" \"bar" } } |] + `shouldRespondWith` ResponseMatcher { + matchBody = Just [json| [{ "data": { "escaped":" \"bar" } }] |] + , matchStatus = 200 + , matchHeaders = [] + } + describe "Row level permission" $ it "set user_id when inserting rows" $ do let auth = authHeaderJWT "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicG9zdGdyZXN0X3Rlc3RfYXV0aG9yIiwiaWQiOiJqZG9lIn0.y4vZuu1dDdwAl0-S00MCRWRYMlJ5YAMSir6Es6WtWx0"