diff --git a/src/PostgREST/ApiRequest/QueryParams.hs b/src/PostgREST/ApiRequest/QueryParams.hs index c3f20c6c0..a48268b06 100644 --- a/src/PostgREST/ApiRequest/QueryParams.hs +++ b/src/PostgREST/ApiRequest/QueryParams.hs @@ -328,11 +328,39 @@ pFieldForest = pFieldTree `sepBy1` lexeme (char ',') pStar :: Parser Text pStar = string "*" $> "*" +-- | +-- Parse field names +-- +-- >>> P.parse pFieldName "" "identifier" +-- Right "identifier" +-- +-- >>> P.parse pFieldName "" "identifier with spaces" +-- Right "identifier with spaces" +-- +-- >>> P.parse pFieldName "" "identifier-with-dashes" +-- Right "identifier-with-dashes" +-- +-- >>> P.parse pFieldName "" "123" +-- Right "123" +-- +-- >>> P.parse pFieldName "" "_" +-- Right "_" +-- +-- >>> P.parse pFieldName "" "$" +-- Right "$" +-- +-- >>> P.parse pFieldName "" ":" +-- Left (line 1, column 1): +-- unexpected ":" +-- expecting field name (* or [a..z0..9_ $]) +-- +-- >>> P.parse pFieldName "" "\":\"" +-- Right ":" pFieldName :: Parser Text pFieldName = pQuotedValue <|> T.intercalate "-" . map toS <$> (many1 pIdentifierChar `sepBy1` dash) - "field name (* or [a..z0..9_])" + "field name (* or [a..z0..9_ $])" where isDash :: GenParser Char st () isDash = try ( char '-' >> notFollowedBy (char '>') ) diff --git a/test/spec/Feature/Query/AndOrParamsSpec.hs b/test/spec/Feature/Query/AndOrParamsSpec.hs index 0048458df..246ed6dbc 100644 --- a/test/spec/Feature/Query/AndOrParamsSpec.hs +++ b/test/spec/Feature/Query/AndOrParamsSpec.hs @@ -200,7 +200,7 @@ spec actualPgVersion = it "cannot have zero conditions" $ get "/entities?or=()" `shouldRespondWith` [json|{ - "details": "unexpected \")\" expecting field name (* or [a..z0..9_]), negation operator (not) or logic operator (and, or)", + "details": "unexpected \")\" expecting field name (* or [a..z0..9_ $]), negation operator (not) or logic operator (and, or)", "message": "\"failed to parse logic tree (())\" (line 1, column 4)", "code": "PGRST100", "hint": null diff --git a/test/spec/Feature/Query/InsertSpec.hs b/test/spec/Feature/Query/InsertSpec.hs index 3392a13d0..0d00c410c 100644 --- a/test/spec/Feature/Query/InsertSpec.hs +++ b/test/spec/Feature/Query/InsertSpec.hs @@ -415,7 +415,7 @@ spec actualPgVersion = do {"id": 204, "body": "yyy"}, {"id": 205, "body": "zzz"}]|] `shouldRespondWith` - [json| {"details":"unexpected end of input expecting field name (* or [a..z0..9_])","message":"\"failed to parse columns parameter ()\" (line 1, column 1)","code":"PGRST100","hint":null} |] + [json| {"details":"unexpected end of input expecting field name (* or [a..z0..9_ $])","message":"\"failed to parse columns parameter ()\" (line 1, column 1)","code":"PGRST100","hint":null} |] { matchStatus = 400 , matchHeaders = [] }