From 42f1eabb2c984a7d30ea8b90710c68aff8af9f97 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 18 Aug 2021 19:00:53 +0200 Subject: [PATCH] fix(csv): less quoting in semicolon separated lists --- src/Utils/Csv.hs | 4 +++- test/Utils/CsvSpec.hs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Utils/Csv.hs b/src/Utils/Csv.hs index 0a1d1d34d..850ef9af1 100644 --- a/src/Utils/Csv.hs +++ b/src/Utils/Csv.hs @@ -140,7 +140,9 @@ instance ToField a => ToField (CsvSemicolonList a) where fs = map toField xs encOpts = defaultEncodeOptions { encDelimiter = fromIntegral $ ord ';' - , encQuoting = bool QuoteMinimal QuoteAll $ all null fs + , encQuoting = case fs of + [fStr] | null fStr -> QuoteAll + _other -> QuoteMinimal , encUseCrLf = True } diff --git a/test/Utils/CsvSpec.hs b/test/Utils/CsvSpec.hs index ce556647a..b4f1c16c0 100644 --- a/test/Utils/CsvSpec.hs +++ b/test/Utils/CsvSpec.hs @@ -32,7 +32,7 @@ spec = modifyMaxSuccess (* 10) . parallel $ do test ["foo", "bar"] "foo;bar" test [] "" test [""] "\"\"" - test ["", ""] "\"\";\"\"" + test ["", ""] ";" test ["foo", ""] "foo;" test ["", "foo"] ";foo" test ["", "", "foo", ""] ";;foo;"