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

empty first record is not skipped if it contains a BOM sequence #394

Closed
dariusheivazi opened this issue Aug 27, 2020 · 3 comments
Closed

Comments

@dariusheivazi
Copy link

dariusheivazi commented Aug 27, 2020

@dariusheivazi I'm guilty of naming stuff poorly 😉 Reader::skipEmptyRecords is the default. So records deemed empty are already removed.

In you case I think the first line is technically not empty so the only way to remove it is to filter it out using the Statement object. At least that's what I understood from your explanation.

The library does not skip empty records as it is promised in documentation: By default the CSV document normalization removes empty records.
I investigated the flow. The problem comes from the normalizing function. If the first record is empty, it does not skip that. In Issue 393 I tried to explaine it. Technically first line may contain BOM, so the normalizing funtion does not find it as null. The resolution is: makethe normalizing funtion a little bit more smart. That may be done by changing the Line 256 of file Reader.php:
FROM
return is_array($record) && ($this->is_empty_records_included || $record != [null]);
TO:
return is_array($record) && ($this->is_empty_records_included || ($record != [null] && $record != [$this->input_bom]));

and It should work, of course if this does not cuase BC break. Anyway. Thanks for this great library. I hope you see this comment.

Originally posted by @dariusheivazi in #393 (comment)

nyamsprod added a commit that referenced this issue Aug 31, 2020
@nyamsprod nyamsprod mentioned this issue Aug 31, 2020
@nyamsprod nyamsprod changed the title The library does not skip empty records as it is promised in documentation empty first record is not skipped if it contains a BOM sequence Aug 31, 2020
@nyamsprod
Copy link
Member

@dariusheivazi a PR has been created with the bug fix could you test the branch to see if it behave as expected.

@dariusheivazi
Copy link
Author

@dariusheivazi a PR has been created with the bug fix could you test the branch to see if it behave as expected.

@nyamsprod, Hi, The PR works like a charm. I tested it, and it works perfectly (at least for my case). Thanks a lot.

@nyamsprod
Copy link
Member

Bug fix merged to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants