imp: csv: check assigned account names are valid (parseable) (#1978)
This commit is contained in:
parent
c95c4ca8d6
commit
dfebf3174c
@ -73,7 +73,7 @@ import Text.Printf (printf)
|
|||||||
|
|
||||||
import Hledger.Data
|
import Hledger.Data
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
import Hledger.Read.Common (aliasesFromOpts, Reader(..), InputOpts(..), amountp, statusp, journalFinalise )
|
import Hledger.Read.Common (aliasesFromOpts, Reader(..), InputOpts(..), amountp, statusp, journalFinalise, accountnamep )
|
||||||
|
|
||||||
--- ** doctest setup
|
--- ** doctest setup
|
||||||
-- $setup
|
-- $setup
|
||||||
@ -1199,7 +1199,12 @@ getAccount rules record mamount mbalance n =
|
|||||||
-- accountN is set to the empty string - no posting will be generated
|
-- accountN is set to the empty string - no posting will be generated
|
||||||
Just "" -> Nothing
|
Just "" -> Nothing
|
||||||
-- accountN is set (possibly to "expenses:unknown"! #1192) - mark it final
|
-- accountN is set (possibly to "expenses:unknown"! #1192) - mark it final
|
||||||
Just a -> Just (a, True)
|
Just a ->
|
||||||
|
-- Check it and reject if invalid.. sometimes people try
|
||||||
|
-- to set an amount or comment along with the account name.
|
||||||
|
case parsewith (accountnamep >> eof) a of
|
||||||
|
Left e -> usageError $ errorBundlePretty e
|
||||||
|
Right _ -> Just (a, True)
|
||||||
-- accountN is unset
|
-- accountN is unset
|
||||||
Nothing ->
|
Nothing ->
|
||||||
case (mamount, mbalance) of
|
case (mamount, mbalance) of
|
||||||
|
|||||||
@ -1059,7 +1059,16 @@ fields date, b, c
|
|||||||
$ ./csvtest.sh
|
$ ./csvtest.sh
|
||||||
>=
|
>=
|
||||||
|
|
||||||
|
# 54. Some validation is done on account name assignments; trying to
|
||||||
|
# also set an amount there (with 2+ spaces) will be rejected. (#1978)
|
||||||
|
<
|
||||||
|
2022-01-01,1
|
||||||
|
RULES
|
||||||
|
fields date,amt
|
||||||
|
account1 assets %amt
|
||||||
|
$ ./csvtest.sh
|
||||||
|
>2 /unexpected space/
|
||||||
|
>=1
|
||||||
|
|
||||||
## .
|
## .
|
||||||
#<
|
#<
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user