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
This commit is contained in:
parent
7394441728
commit
29211868bb
@ -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 "\"" "\""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user