lib: Properly escape quotes in csv output.
This commit is contained in:
parent
4609e79f2c
commit
4cb9dfb5b8
@ -813,8 +813,8 @@ parseResultToCsv = toListList . unpackFields
|
||||
|
||||
printCSV :: CSV -> TL.Text
|
||||
printCSV = TB.toLazyText . unlinesB . map printRecord
|
||||
where printRecord = mconcat . map TB.fromText . intersperse "," . map printField
|
||||
printField = wrap "\"" "\"" . T.replace "\"" "\\\"\\\""
|
||||
where printRecord = foldMap TB.fromText . intersperse "," . map printField
|
||||
printField = wrap "\"" "\"" . T.replace "\"" "\"\""
|
||||
|
||||
-- | Return the cleaned up and validated CSV data (can be empty), or an error.
|
||||
validateCsv :: CsvRules -> Int -> Either String CSV -> Either String [CsvRecord]
|
||||
|
||||
@ -143,3 +143,14 @@ hledger -f - balance -b 2016/10 -e 2016/11
|
||||
>>>2
|
||||
>>>= 0
|
||||
|
||||
# 7. Test csv output
|
||||
hledger -f - balance -N --output-format=csv
|
||||
<<<
|
||||
2021-01-01 Test
|
||||
Assets:ABC "AB.C" 1
|
||||
Assets:Cash -$1
|
||||
>>>
|
||||
"account","balance"
|
||||
"Assets:ABC","""AB.C"" 1"
|
||||
"Assets:Cash","$-1"
|
||||
>>>= 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user