From 29211868bb56112a7781defaedf2301d4115ca21 Mon Sep 17 00:00:00 2001 From: Jacek Generowicz Date: Sat, 30 Nov 2019 14:34:59 +0100 Subject: [PATCH] Fix issue 457 Issue #457 pointed out that commands such as hledger ui 'amt:>200' failed. This was becasue the process of dispatching from `hledger ui` to `hledger-ui` (note addition of `-`) lost the quotes around `amt:>20` and the `>` character was interpreted as a shell redirection operator, rather than as part of the argument. The machinery for quoting or escaping arguements which cointain characters which require quoting or escaping (thus far whitespace and quotes) already existed. This solution simply adds shell stdio redirection characters to this set. Fixes #457 --- hledger-lib/Hledger/Utils/String.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Utils/String.hs b/hledger-lib/Hledger/Utils/String.hs index 03342317d..389c6d2fb 100644 --- a/hledger-lib/Hledger/Utils/String.hs +++ b/hledger-lib/Hledger/Utils/String.hs @@ -111,7 +111,7 @@ 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) = "\"" ++ escapeDoubleQuotes s ++ "\"" +quoteIfNeeded s | any (`elem` s) (quotechars++whitespacechars++redirectchars) = "\"" ++ escapeDoubleQuotes s ++ "\"" | otherwise = s -- | Single-quote this string if it contains whitespace or double-quotes. -- No good for strings containing single quotes. @@ -119,9 +119,10 @@ singleQuoteIfNeeded :: String -> String singleQuoteIfNeeded s | any (`elem` s) whitespacechars = "'"++s++"'" | otherwise = s -quotechars, whitespacechars :: [Char] +quotechars, whitespacechars, redirectchars :: [Char] quotechars = "'\"" whitespacechars = " \t\n\r" +redirectchars = "<>" escapeDoubleQuotes :: String -> String escapeDoubleQuotes = regexReplace "\"" "\""