wimverstuyf / php-coda-parser

PHP parser for Belgian CODA banking files
GNU Lesser General Public License v3.0
41 stars 25 forks source link

Some CODA files are having lines with 130 characters instead of 128. #19

Open sbichara opened 3 years ago

sbichara commented 3 years ago

Hi, First of all many thx for this useful package.

I noticed that the ING CODA files are having lines with 130 characters instead of 128 which then throws a fatal exception in the parser. By "trimming" the line, the issue is solved (I added the trim in the function Parse of the class LinesParser.php).

foreach($codaLines as $line) {
            if (!empty($line)) {
                /** @var LineInterface|null $lineObject */
                $lineObject = null;
                $line = trim($line);

Thank you.

Sélim

kouinkouin commented 3 years ago

Hi, Not better to put the trim before the if (!empty($line)) {, to avoid to treat an empty line?

And, what happens if the "trimmed" line has 127 char (because the 128th was a space)? (i don't know if the last char can be a space...)

sbichara commented 3 years ago

Hi, I agree with both of your comments. In the end you need to ensure that the line has the correct length after the trim and see whether it's relevant to process it or not.

wimverstuyf commented 3 years ago

Hi Sélim,

Strange that the ING-file does not have 128 characters. The 2 extra character are only white spaces? Adding a trim would be a good solution. The last character (character 128) should always be a number so no need to add a safeguard against trimming this value.

Can you create a PR + unittest? Then I'll take a look at it.

Wim