diff --git a/hledger-lib/Hledger/Utils/String.hs b/hledger-lib/Hledger/Utils/String.hs index 817c4799f..f15a80074 100644 --- a/hledger-lib/Hledger/Utils/String.hs +++ b/hledger-lib/Hledger/Utils/String.hs @@ -118,13 +118,17 @@ underline s = s' ++ replicate (length s) '-' ++ "\n" -- | Double-quote this string if it contains whitespace, single quotes -- or double-quotes, escaping the quotes as needed. quoteIfNeeded :: String -> String -quoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars++redirectchars) = show s +quoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars++redirectchars) = showChar '"' $ escapeQuotes s "\"" | otherwise = s + where + escapeQuotes [] x = x + escapeQuotes ('"':cs) x = showString "\\\"" $ escapeQuotes cs x + escapeQuotes (c:cs) x = showChar c $ escapeQuotes cs x -- | Single-quote this string if it contains whitespace or double-quotes. -- No good for strings containing single quotes. singleQuoteIfNeeded :: String -> String -singleQuoteIfNeeded s | any (`elem` s) whitespacechars = "'"++s++"'" +singleQuoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars) = "'"++s++"'" | otherwise = s quotechars, whitespacechars, redirectchars :: [Char] diff --git a/tests/i18n/unicode-account-matching.test b/tests/i18n/unicode-account-matching.test index dc87ebce2..4627ca7bd 100644 --- a/tests/i18n/unicode-account-matching.test +++ b/tests/i18n/unicode-account-matching.test @@ -6,3 +6,12 @@ hledger -f - register τράπ >>> 2009-01-01 проверка τράπεζα 10 руб 10 руб >>>=0 + +hledger -f - balance -N " ét" +<<< +2020-09-19 Test + assets:a ét 5 + assets:b +>>> + 5 assets:a ét +>>>=0