Prevent inserting CSV with varying row length
This commit is contained in:
@@ -99,7 +99,9 @@ userIntent schema req reqBody =
|
|||||||
(JSON.eitherDecode reqBody)
|
(JSON.eitherDecode reqBody)
|
||||||
Right TextCSV ->
|
Right TextCSV ->
|
||||||
either (PayloadParseError . cs)
|
either (PayloadParseError . cs)
|
||||||
(PayloadJSON . csvToJson)
|
(\val -> case ensureUniform (csvToJson val) of
|
||||||
|
Nothing -> PayloadParseError "All lines must have same number of fields"
|
||||||
|
Just json -> PayloadJSON json)
|
||||||
(CSV.decodeByName reqBody)
|
(CSV.decodeByName reqBody)
|
||||||
Left accept ->
|
Left accept ->
|
||||||
PayloadParseError $
|
PayloadParseError $
|
||||||
@@ -177,11 +179,11 @@ type CsvData = V.Vector (M.HashMap T.Text BL.ByteString)
|
|||||||
The reason for its odd signature is so that it can compose
|
The reason for its odd signature is so that it can compose
|
||||||
directly with CSV.decodeByName
|
directly with CSV.decodeByName
|
||||||
-}
|
-}
|
||||||
csvToJson :: (CSV.Header, CsvData) -> UniformObjects
|
csvToJson :: (CSV.Header, CsvData) -> JSON.Array
|
||||||
csvToJson (_, vals) =
|
csvToJson (_, vals) =
|
||||||
UniformObjects $ V.map rowToJsonObj vals
|
V.map rowToJsonObj vals
|
||||||
where
|
where
|
||||||
rowToJsonObj =
|
rowToJsonObj = JSON.Object .
|
||||||
M.map (\str ->
|
M.map (\str ->
|
||||||
if str == "NULL"
|
if str == "NULL"
|
||||||
then JSON.Null
|
then JSON.Null
|
||||||
|
|||||||
Reference in New Issue
Block a user