From 7d1e6d7d12f3c3a042661c1d6963523b5d5f676b Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Tue, 1 Sep 2020 11:41:55 +1000 Subject: [PATCH] lib: Fix quoteIfNeeded so it actually escapes quotes. --- hledger-lib/Hledger/Utils/String.hs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/hledger-lib/Hledger/Utils/String.hs b/hledger-lib/Hledger/Utils/String.hs index 870063a63..21aee9049 100644 --- a/hledger-lib/Hledger/Utils/String.hs +++ b/hledger-lib/Hledger/Utils/String.hs @@ -13,7 +13,6 @@ module Hledger.Utils.String ( singleQuoteIfNeeded, -- quotechars, -- whitespacechars, - escapeQuotes, words', unwords', stripAnsi, @@ -120,8 +119,9 @@ 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) = "\"" ++ escapeDoubleQuotes s ++ "\"" +quoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars++redirectchars) = show s | otherwise = s + -- | Single-quote this string if it contains whitespace or double-quotes. -- No good for strings containing single quotes. singleQuoteIfNeeded :: String -> String @@ -133,12 +133,6 @@ quotechars = "'\"" whitespacechars = " \t\n\r" redirectchars = "<>" -escapeDoubleQuotes :: String -> String -escapeDoubleQuotes = id -- regexReplace "\"" "\"" - -escapeQuotes :: String -> String -escapeQuotes = id -- regexReplace "([\"'])" "\\1" - -- | Quote-aware version of words - don't split on spaces which are inside quotes. -- NB correctly handles "a'b" but not "''a''". Can raise an error if parsing fails. words' :: String -> [String]