Skip to content

Strip enclosing quotes before unescaping CSV fields - #1059

Merged
michelebastione merged 1 commit into
mini-software:masterfrom
vtxe02023274:csv-quote-only-fields
Nov 19, 2026
Merged

michelebastione merged 1 commit into
mini-software:masterfrom
vtxe02023274:csv-quote-only-fields

Conversation

@vtxe02023274

@vtxe02023274 vtxe02023274 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1058.

CsvReader.Split replaced "" with " before stripping the enclosing quotes, so a field made only of quotes lost one: """" was read as an empty string and """""" as ". MiniExcel's own export writes " and "" that way, so they did not round-trip. The enclosing quotes are now stripped first and "" is unescaped afterwards. Fields that contain any other character give the same result as before.

Test: MiniExcelCsvTests.ReadFieldsMadeOnlyOfQuotesTest exports ", "", "a", a" and "a and reads them back with hasHeaderRow: true. It fails on master ("" instead of ") and passes with this change.

Ran (Windows): dotnet test tests/MiniExcel.Csv.Tests on net8.0, net10.0 and net11.0, 90 passed each. net9.0 not run locally (no runtime here).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed CSV import handling for fields containing only quotation marks or partially quoted text. These values now retain their original content when exported and imported, including when the CSV includes a header.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The CSV reader now strips boundary quotes before unescaping doubled quotes. A new test checks that quote-containing values round-trip through CSV export and import.

Changes: CSV Quote-Only Field Round-Trip

Layer / File(s) Summary
Quote parsing and round-trip test
src/MiniExcel.Csv/CsvReader.cs, tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvTests.cs
CsvReader.Split strips boundary quotes before unescaping doubled quotes. The new test checks that five quote-containing values import unchanged after export.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: michelebastione

Merge Risk: Minimal · up to 26140

This change fixes round-tripping of CSV fields made only of double quotes, and fields with other characters are unaffected. A regression test covers the reported cases. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change that matters: CsvReader.Split now strips enclosing quotes before unescaping doubled quotes. The raw summary and PR objectives both describe this same reordering as the fix f…
Linked Issues check Passed Issue #1058 requires quote-only CSV fields to round-trip. Expected: " reads back as " and "" reads back as "". The change in src/MiniExcel.Csv/CsvReader.cs (Split) now applies DoubleQuotesRege…
Out of Scope Changes check Passed The whole-PR diff (merge base c7fb0bd to head 261403b) changes two files. CsvReader.cs changes only the operation order in Split, which is the fix the issue requests. The test file adds ReadFieldsMade…
Full details: Title check

Explanation

The title names the change that matters: CsvReader.Split now strips enclosing quotes before unescaping doubled quotes. The raw summary and PR objectives both describe this same reordering as the fix for quote-only CSV fields (issue #1058). The title is specific and concise, and it matches the one-line source change.

Full details: Linked Issues check

Explanation

Issue #1058 requires quote-only CSV fields to round-trip. Expected: " reads back as " and "" reads back as "". The change in src/MiniExcel.Csv/CsvReader.cs (Split) now applies DoubleQuotesRegexImpl.Replace(s, "") before s.Replace("""", """). The enclosing quotes are removed first, then doubled quotes are unescaped. For """" (exported "), the result is ". For """""" (exported ""), the result is "". This matches the issue's expected behavior. The issue states that fields with other characters already round-trip. The diff keeps their result the same for the cases checked ("a", a", "a, and an embedded escaped quote). Test ReadFieldsMadeOnlyOfQuotesTest in tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvTests.cs covers the quote-only cases and the other cases from the issue. The PR reports a local test run (90 passed on net8.0, net10.0, net11.0). That run is author-reported and was not re-executed here. The assessment assumes DoubleQuotesRegexImpl removes only one boundary quote at each end, as the issue's analysis implies. This was not re-read in this review.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff (merge base c7fb0bd to head 261403b) changes two files. CsvReader.cs changes only the operation order in Split, which is the fix the issue requests. The test file adds ReadFieldsMadeOnlyOfQuotesTest, which supports the fix and is in scope. No unrelated changes were found in the reviewed evidence. The PR description and the raw summary report no other files changed.

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: acc418e1-761c-4f8e-996a-ca2e796d98e4
Commits

Reviewing files that changed from the base of the PR and between c7fb0bd and 261403b.

Files selected for processing: 2

  • src/MiniExcel.Csv/CsvReader.cs
  • tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@menes97 menes97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Stripping the enclosing quotes before unescaping "" is the right order, and the fix is minimal.

I checked it out and ran MiniExcel.Csv.Tests on net10.0 (on a tr-TR machine): 90/90 pass. With CsvReader.cs reverted to the base, ReadFieldsMadeOnlyOfQuotesTest fails as described (a " field reads back as an empty string), and the other 89 still pass.

Optional: a value that mixes the separator with quotes, such as a,"b", could be added to the same test, so the regex split and the unescape order are covered together. Not a blocker.

@michelebastione
michelebastione merged commit 17fc565 into mini-software:master Nov 19, 2026
9 of 11 checks passed
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

Successfully merging this pull request may close these issues.

CSV fields made only of double quotes are read back wrong

3 participants