diff --git a/src/PostgREST/Parsers.hs b/src/PostgREST/Parsers.hs index 235962811..0892eba0b 100644 --- a/src/PostgREST/Parsers.hs +++ b/src/PostgREST/Parsers.hs @@ -18,6 +18,7 @@ import Data.Tree import Network.Wai (Request, pathInfo, queryString) import PostgREST.Types import Text.ParserCombinators.Parsec hiding (many, (<|>)) + parseGetRequest :: Request -> Either ParseError ApiRequest parseGetRequest httpRequest = foldr addFilter <$> (addOrder <$> apiRequest <*> ord) <*> flts @@ -77,7 +78,7 @@ lexeme p = ws *> p <* ws pTreePath :: Parser (Path,Field) pTreePath = do p <- pFieldName `sepBy1` pDelimiter - jp <- optionMaybe ( string "->" >> pJsonPath) + jp <- optionMaybe pJsonPath let pp = map cs p jpp = map cs <$> jp return (init pp, (last pp, jpp)) @@ -98,14 +99,14 @@ pFieldName :: Parser Text pFieldName = cs <$> (many1 (letter <|> digit <|> oneOf "_") "field name (* or [a..z0..9_])") -pJsonPathDelimiter :: Parser Text -pJsonPathDelimiter = cs <$> (try (string "->>") <|> string "->") +pJsonPathStep :: Parser Text +pJsonPathStep = cs <$> try (string "->" *> pFieldName) pJsonPath :: Parser [Text] -pJsonPath = pFieldName `sepBy1` pJsonPathDelimiter +pJsonPath = (++) <$> many pJsonPathStep <*> ( (:[]) <$> (string "->>" *> pFieldName) ) pField :: Parser Field -pField = lexeme $ (,) <$> pFieldName <*> optionMaybe ( pJsonPathDelimiter *> pJsonPath) +pField = lexeme $ (,) <$> pFieldName <*> optionMaybe pJsonPath pSelect :: Parser SelectItem pSelect = lexeme $ diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 50f21361b..c9b75813c 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -303,7 +303,6 @@ spec = get "/json?data->foo->>bar=not.eq.baz" `shouldRespondWith` [json| [] |] it "can filter by properties inside json column using ->>" $ do - pendingWith "see issue #334" get "/json?data->>id=eq.1" `shouldRespondWith` [json| [{"data": {"id": 1, "foo": {"bar": "baz"}}}] |]