fruitl00p / php-mt940

A mt940 parser in PHP
MIT License
103 stars 60 forks source link

price is not correctly parsed #53

Closed ixp-nl closed 6 years ago

ixp-nl commented 6 years ago

Example line from MT940 file :61:1807300730D28,5N132000002018827922//B8G30PGA01UD901N

Correct price: Debit 28,50 Parsed price: Debit 901,00

Problem comes from the regex in parseTransactionPrice in the Engine.php The pattern /^:61:.*[CD]([\d,\.]+)N/i has a .* in it which is greedy, when you add a ? after the .* it becomes non greedy and matches the first [CD]([\d,\.]+)N in the line.

Correct regex: /^:61:.*?[CD]([\d,\.]+)N/i

fruitl00p commented 6 years ago

@ixp-nl thanks. I've updated the regex and added a unittest to confirm (and prevent regressions in the future)

Again, thanks for the heads up.