git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix: allow empty hstore's and enfore complete parse.
commit96e4e1ad3280e1c5f77451fe83008b9f807a3129 authorSimon Meier <simon.meier@erudify.ch> dateMon 29 Apr 2013, 17:30 (13 years ago) parentebe2d23
3 files changed+11−16
.ghci+2 postgresql-simple.cabal+1−1 src/Database/PostgreSQL/Simple/HStore/Implementation.hs+8−15
.ghcinew file+2
@@ -0,0 +1,2 @@
1+:set -isrc
2+:set Wall
postgresql-simple.cabal+1−1
@@ -1,5 +1,5 @@
11Name: postgresql-simple
2−Version: 0.3.1.0
2+Version: 0.3.1.1
33Synopsis: Mid-Level PostgreSQL client library
44Description:
55 Mid-Level PostgreSQL client library, forked from mysql-simple.
src/Database/PostgreSQL/Simple/HStore/Implementation.hs+8−15
@@ -24,7 +24,6 @@ import qualified Data.Attoparsec.ByteString.Char8 as P (isSpace_w8)
2424import qualified Data.ByteString as BS
2525import Data.ByteString.Internal (c2w, w2c)
2626import qualified Data.ByteString.Lazy as BL
27−import qualified Data.ByteString.Lazy.Internal as BL
2827import Data.Map(Map)
2928import qualified Data.Map as Map
3029import Data.Text(Text)
@@ -129,7 +128,7 @@ instance FromField HStoreList where
129128 else case mdat of
130129 Nothing -> returnError UnexpectedNull f ""
131130 Just dat ->
132− case P.parseOnly parseHStore dat of
131+ case P.parseOnly (parseHStore <* P.endOfInput) dat of
133132 Left err ->
134133 returnError ConversionFailed f err
135134 Right (Left err) ->
@@ -152,19 +151,13 @@ instance FromField HStoreMap where
152151 where convert (HStoreList xs) = HStoreMap (Map.fromList xs)
153152
154153parseHStore :: P.Parser (Either UnicodeException HStoreList)
155−parseHStore = skipWhiteSpace >> loop id
154+parseHStore =
155+ reverseEither [] <$> P.sepBy' (skipWhiteSpace *> parseHStoreKeyVal)
156+ (skipWhiteSpace *> P.word8 (c2w ','))
156157 where
157− loop acc = do
158− mkv <- parseHStoreKeyVal
159− case mkv of
160− Left err -> return (Left err)
161− Right kv -> do
162− skipWhiteSpace
163− (do
164− _ <- P.word8 (c2w ',')
165− skipWhiteSpace
166− loop (acc . (kv:))
167− ) <|> return (Right (HStoreList (acc [kv])))
158+ reverseEither acc [] = Right (HStoreList acc)
159+ reverseEither _acc ((Left err):_xs) = Left err
160+ reverseEither acc ((Right x ):xs) = reverseEither (x:acc) xs
168161
169162parseHStoreKeyVal :: P.Parser (Either UnicodeException (Text,Text))
170163parseHStoreKeyVal = do
@@ -199,7 +192,7 @@ parseHStoreTexts :: ([Text] -> [Text])
199192parseHStoreTexts acc = do
200193 mchunk <- TS.decodeUtf8' <$> P.takeWhile (not . isSpecialChar)
201194 case mchunk of
202− Left err -> return (Left err)
195+ Left err -> return (Left err)
203196 Right chunk ->
204197 (do
205198 _ <- P.word8 (c2w '\\')