You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Leave out CSV fields past the last header instead of throwing KeyNotFoundException - #1072
With hasHeaderRow: true, CsvReader.QueryAsync looked up headRows[i] for every field of a row, so a row with more fields than the header (a trailing separator is enough) threw KeyNotFoundException. The header branch now stops at the header count, so fields without a column name are left out, as the OpenXml reader does for cells without a header. Rows with fewer fields still throw ColumnNotFoundException or are filled by FillMissingColumns as before, and reading without a header row is unchanged.
Test:GithubIssuesTests.ExtraFieldsWithHeaderRow reads A,B\n1,2,\n3,4,5,6\n with hasHeaderRow: true through Query, QueryAsync and GetDataReader. It fails on master (KeyNotFoundException: The given key '2' was not present in the dictionary.) and passes with this change.
Ran (Windows): dotnet test tests/MiniExcel.Csv.Tests on net8.0, net10.0 and net11.0, 92 passed each. dotnet test tests/MiniExcel.OpenXml.Tests -f net10.0, 564 passed. net9.0 not run locally (no runtime here).
Summary by CodeRabbit
Bug Fixes
CSV imports with a header row now ignore extra fields that have no corresponding header, rather than failing when processing them. This behavior applies to both synchronous and asynchronous queries. Fields with matching headers continue to be available by name, and existing validation for rows with fewer fields than headers remains unchanged.
No actionable comments were generated in the recent review.
Walkthrough
Header-row parsing now skips CSV fields beyond the available headers. Tests cover synchronous and asynchronous queries and confirm that the data reader exposes only the named fields.
Header-row parsing limits assignments to the number of available headers. Tests verify that synchronous and asynchronous queries and the data reader omit extra fields, including an empty trailing field.
CSV rows with more fields than headers no longer throw KeyNotFoundException when a header row is used; the extra fields are omitted. The change is small and localized, and I found no merge-blocking risk.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main behavior change: CSV fields past the last header are left out instead of throwing KeyNotFoundException. The raw summary says header-row parsing now stops at the smaller of the…
Linked Issues check
[#1071] The requirement: with hasHeaderRow: true, fields past the last header must be omitted instead of throwing KeyNotFoundException. The reviewed head changes CsvReader.QueryAsync (src/MiniExcel.Cs…
Out of Scope Changes check
The whole-PR diff against the merge base 27caf1e touches two files: src/MiniExcel.Csv/CsvReader.cs (a 4-line change plus one comment, limited to the header-row field loops) and tests/MiniExcel.Csv.Tes…
Full details: Title check
Explanation
The title names the main behavior change: CSV fields past the last header are left out instead of throwing KeyNotFoundException. The raw summary says header-row parsing now stops at the smaller of the field count and the header count, and the added test covers trailing fields with headers A,B. The title matches the changeset and the linked issue objective.
Full details: Linked Issues check
Explanation
[#1071] The requirement: with hasHeaderRow: true, fields past the last header must be omitted instead of throwing KeyNotFoundException. The reviewed head changes CsvReader.QueryAsync (src/MiniExcel.Csv/CsvReader.cs). The header branch now computes fieldCount = Math.Min(read.Length, headRows.Count) and iterates only to fieldCount in both the ReadEmptyFieldsAsDefault and the non-default branch. For 'A,B' with row '1,2,', the row yields A = "1" and B = "2" and the extra field is dropped, as the issue expects. The synchronous Query is generated from QueryAsync via [CreateSyncVersion]. GetDataReader is reported in the issue as failing the same way; the diff touches the single shared header loop, and the test ExtraFieldsWithHeaderRow covers Query, QueryAsync and GetDataReader. Rows with fewer fields still reach the unchanged ColumnNotFoundException check or FillMissingColumns handling. The no-header path (body branch) is unchanged, as the issue requires. Test results were reported by the author and were not re-run here. Test source was not inspected in this assessment.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base 27caf1e touches two files: src/MiniExcel.Csv/CsvReader.cs (a 4-line change plus one comment, limited to the header-row field loops) and tests/MiniExcel.Csv.Tests/Issues/GithubIssuesTests.cs (new ExtraFieldsWithHeaderRow test covering the issue scenario). Both changes connect directly to #1071. No unrelated refactoring or behavior change was found in the reviewed diff. The reviewed diff for CsvReader.cs was read in full; the test file was assessed from the summary only.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Fix failing CI checks
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 98a16560-d5d6-4867-a235-a496305c2f35
Commits
Reviewing files that changed from the base of the PR and between 27caf1e and 6ee7aa7.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1071.
With
hasHeaderRow: true,CsvReader.QueryAsynclooked upheadRows[i]for every field of a row, so a row with more fields than the header (a trailing separator is enough) threwKeyNotFoundException. The header branch now stops at the header count, so fields without a column name are left out, as the OpenXml reader does for cells without a header. Rows with fewer fields still throwColumnNotFoundExceptionor are filled byFillMissingColumnsas before, and reading without a header row is unchanged.Test:
GithubIssuesTests.ExtraFieldsWithHeaderRowreadsA,B\n1,2,\n3,4,5,6\nwithhasHeaderRow: truethroughQuery,QueryAsyncandGetDataReader. It fails onmaster(KeyNotFoundException: The given key '2' was not present in the dictionary.) and passes with this change.Ran (Windows):
dotnet test tests/MiniExcel.Csv.Testson net8.0, net10.0 and net11.0, 92 passed each.dotnet test tests/MiniExcel.OpenXml.Tests -f net10.0, 564 passed. net9.0 not run locally (no runtime here).Summary by CodeRabbit