Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

account directives should disallow parentheses, square brackets #1915

Closed
simonmichael opened this issue Aug 12, 2022 · 9 comments · Fixed by #1987 or #1990
Closed

account directives should disallow parentheses, square brackets #1915

simonmichael opened this issue Aug 12, 2022 · 9 comments · Fixed by #1987 or #1990
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. journal The journal file format, and its features.

Comments

@simonmichael
Copy link
Owner

hledger's journal reader accepts but misparses parentheses/square brackets in account directives (reported by dentalfloss). Eg:

account (a)

2022-01-01
    a         0
$ hledger -f a.j accounts
(a)
a
$ hledger -f a.j check accounts
hledger: Error: /Users/simon/src/hledger/a.j:4:
  | 2022-01-01
4 |     a               0
  |     ^

Strict account checking is enabled, and
account "a" has not been declared.
@simonmichael simonmichael added A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. journal The journal file format, and its features. labels Aug 12, 2022
@chrislemaire
Copy link
Contributor

So would the desired behaviour here be the rejection of accounts with parentheses in them? Or would it be that this declaration is translated to an account name of a, so that this example would check to be a well-formed journal?

@chrislemaire
Copy link
Contributor

When looking through the relevant functions, I found this comment explaining the need to be able to parse bracketed accounts. Any account names with special characters really:

-- | Parse an account name, plus one following space if present.
-- Account names have one or more parts separated by the account separator character,
-- and are terminated by two or more spaces (or end of input).
-- Each part is at least one character long, may have single spaces inside it,
-- and starts with a non-whitespace.
-- Note, this means "{account}", "%^!" and ";comment" are all accepted
-- (parent parsers usually prevent/consume the last).
-- It should have required parts to start with an alphanumeric;
-- for now it remains as-is for backwards compatibility.
accountnamep :: TextParser m AccountName
accountnamep = singlespacedtext1p

I believe the parser should then be adjusted here to not parse on surrounding parentheses and square brackets?

@simonmichael
Copy link
Owner Author

Yes I think parentheses/brackets in account declarations would ideally be rejected as there's no reason for them. But it might be easier to remove and ignore them instead when parsing account directives. There should be a function for that in AccountName or somewhere.

@simonmichael
Copy link
Owner Author

(They are needed when parsing account names in postings, where they have a meaning. )

@simonmichael
Copy link
Owner Author

simonmichael commented Jan 24, 2023

Ahaha. I overlooked that #1987 does not fix this issue. I think account should disallow enclosing parentheses/brackets, ie report an error, not simply ignore them, as they have no purpose in account directives and might cause confusion.

@simonmichael
Copy link
Owner Author

Or rather, it does fix the example I gave, making it not fail. But my intention was to reject account (foo) entirely.

@chrislemaire
Copy link
Contributor

Ah I see, well should be an easy enough addition. I'll add a check in the parser in a new PR.

@chrislemaire
Copy link
Contributor

Would you perhaps also like to reject postings such as the following?

2022-01-01
    [(a)]         0

Because of the confusion accidentally nested brackets may cause. If this would be rejected, users are notified of overly bracketed account names, that would otherwise be completely stripped of their brackets later, causing an account name that appears to be different to be shown.

@simonmichael
Copy link
Owner Author

simonmichael commented Jan 24, 2023

Thanks a lot @chrislemaire!

Re rejecting over-enclosed accounts names in postings.. could you show briefly the sequence of events causing confusion ? Preventing that sounds good, hopefully we haven't introduced a new restriction that users will find arbitrary.

(Are you starting to wish "virtual postings" had never been invented ? I am..)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. journal The journal file format, and its features.
Projects
None yet
2 participants