fix: Ensure head and tail are not called on empty account names.

This commit is contained in:
Stephen Morgan 2021-12-15 15:58:27 +11:00 committed by Simon Michael
parent 88f34063c7
commit e9dd77e82b
2 changed files with 7 additions and 5 deletions

View File

@ -404,8 +404,8 @@ accountNamePostingType a
accountNameWithoutPostingType :: AccountName -> AccountName
accountNameWithoutPostingType a = case accountNamePostingType a of
BalancedVirtualPosting -> T.init $ T.tail a
VirtualPosting -> T.init $ T.tail a
BalancedVirtualPosting -> textUnbracket a
VirtualPosting -> textUnbracket a
RegularPosting -> a
accountNameWithPostingType :: PostingType -> AccountName -> AccountName

View File

@ -169,15 +169,17 @@ stripquotes s = if isSingleQuoted s || isDoubleQuoted s then T.init $ T.tail s e
isSingleQuoted :: Text -> Bool
isSingleQuoted s =
T.length (T.take 2 s) == 2 && T.head s == '\'' && T.last s == '\''
T.length s >= 2 && T.head s == '\'' && T.last s == '\''
isDoubleQuoted :: Text -> Bool
isDoubleQuoted s =
T.length (T.take 2 s) == 2 && T.head s == '"' && T.last s == '"'
T.length s >= 2 && T.head s == '"' && T.last s == '"'
textUnbracket :: Text -> Text
textUnbracket s
| (T.head s == '[' && T.last s == ']') || (T.head s == '(' && T.last s == ')') = T.init $ T.tail s
| T.null s = s
| T.head s == '[' && T.last s == ']' = T.init $ T.tail s
| T.head s == '(' && T.last s == ')' = T.init $ T.tail s
| otherwise = s
-- | Join several multi-line strings as side-by-side rectangular strings of the same height, top-padded.