MoritzR / fints2ledger

A tool for downloading transactions from FinTS banking APIs and sorting them into a ledger journal
MIT License
26 stars 8 forks source link

New fints2ledger can't deal with empty payees #30

Closed varac closed 11 months ago

varac commented 11 months ago

I have a lot of theses matching rules where I want to match a transaction where the payee must empty:

  - fills:
    - match:
        payee: ""
        posting: "Basislastschrift"
        purpose: "Spotify.*"
      fill:
        credit_account: "Expenses:Music"

Latest fints2ledger fails with:

fints2ledger: makeRegexOpts failed
CallStack (from HasCallStack):
  error, called at src/Text/Regex/Base/RegexLike.hs:137:32 in regex-base-0.94.0.2-69b4ec641c8aff5fa1d43081c9aac99741c6c4858c40d670520e7e1e05fde420:Text.Regex.Base.RegexLike

When I remove the payee: "" line it works. Old fints2ledger handled this case fine.

MoritzR commented 11 months ago

Are you sure the old version handled it correctly? Using "" as an regex would match any text, as far as I can see it:

>>> "Matched" if re.match("","") else "No Match"
'Matched'
>>> "Matched" if re.match("","not empty") else "No Match"
'Matched'
>>> "Matched" if re.match("^$","") else "No Match"
'Matched'
>>> "Matched" if re.match("^$","not empty") else "No Match"
'No Match'

If you want to match the empty string, use ^$ instead.

I have to say that I find using "" as a match much more intuitive, though. Maybe requiring regexes there was not the best decision, but that is kind of hard to change now.

I will do something about the error message though.

varac commented 11 months ago

Oh you're right, apparently it never matched but I didn't realize it :facepalm: Using "^$" works ! No, I really like that regex can be used, it makes fints2ledger much more flexbile.