Skip to content

fix: strict csv quoting names where it refuses, stays cancellable and drops any whitespace around a quoted field - #202

Merged
vaceslav merged 2 commits into
mainfrom
fix/201-strict-quote-followups
Nov 27, 2026
Merged

vaceslav merged 2 commits into
mainfrom
fix/201-strict-quote-followups

Conversation

@vaceslav

Copy link
Copy Markdown
Contributor

What and why

The follow-ups the two reviews of #199 left open for CsvQuoteMode.Strict, so that its refusals say where and why, its reads stay cancellable, and its whitespace rule matches the trim.

  • A stray quote that reaches the field limit says so. In strict mode a quote that is never closed reads on to MaxFieldChars. It stays TabularLimitException (limit.exceeded) — a quoted field that long which would have closed later is indistinguishable, and a host answers a limit as an upload too large — but every csv field-limit message now names the row, and in strict mode inside a quoted field it says the quote was never closed within the limit.
  • A refusal inside an archive names the file. ArchiveCursor.ReadRow prefixes a TabularFormatException from the file inside with the entry's path (data/bad.csv: The csv file is not valid at row 2: …), keeping the code and the original as the inner exception. That holds for any file in a zip or tar, a damaged workbook part included.
  • Cancellation reaches the whitespace after a closing quote. The skip had no bound and no check: a closing quote and a few hundred million spaces held a read beyond its token. It now asks for cancellation every 64 K characters, as the row loop does.
  • The whitespace dropped around a quoted field is what a cell is trimmed of anyway, a no-break space included (common in text pasted from spreadsheets and web pages), except a tab that is the delimiter and line endings. It was only space and tab. Consequently Quote may not be whitespace when QuoteMode is Strict (refused when the cursor opens).
  • Strict mode reads quoted text faster. Inside quotes it counts nothing, so its run now ends only at a quote instead of at every delimiter and line break.
  • format.corrupt rather than format.truncated for a file that ends inside a quoted field is kept and explained in the code: a quote left open is far more often a forgotten one than a clipped upload. That whitespace before an opening quote counts towards MaxFieldChars (it is held until the quote shows it is not content) is documented and pinned by a test.

Fixes #201

Measured

  • Default path, 5M-row malformed csv (572 MB), 8 alternating runs on a shared machine: main min 3,082 ms, this branch min 3,070 ms (no change); allocations, rows (5,127,969) and repairs (458) identical.
  • Strict mode, synthetic 74 MB csv of 300,000 rows each with a quoted note of twelve commas and three line breaks, min of 7: main 185 ms, this branch 76 ms.

Tests

New in StrictQuoteTests: the limit message, the blanks counted towards the limit, no-break and em spaces around a quoted field, cancellation inside a run of spaces after a closing quote, a refusal with the closing quote on either side of the 64 K read-buffer edge, blanks before an opening quote crossing that edge, and strict reads of a zip and a tar whose bad entry is named. OptionsValidationTests refuses a whitespace quote in strict mode. The strict round-trip fuzz pads quoted fields with no-break and em spaces too (20,000 cases run locally). The comment of the linear-time test now gives the measured 24 s.

Public API

No new members. Behaviour: CsvCursorOptions with QuoteMode = Strict and a whitespace Quote is now refused (ArgumentOutOfRangeException), and strict mode drops all whitespace, not only space and tab, around a quoted field.

Checklist

  • A test that failed before the change and passes after it (for a fix or a new behaviour).
  • dotnet build and dotnet test pass on net10.0 and net11.0 with zero warnings.
  • If the read path changed: measured, and the numbers are in the description.
  • If an error code was added or changed: ErrorCodes and the guide's error-code table agree.
  • Public API changes are described, and breaking ones are called out.
  • No third-party package in src/.

@vaceslav
vaceslav merged commit 3d4f26b into main Nov 27, 2026
10 checks passed
@vaceslav
vaceslav deleted the fix/201-strict-quote-followups branch November 27, 2026 09:51
vaceslav added a commit that referenced this pull request Nov 27, 2026
🤖 I have created a release *beep* *boop*
---


## [0.9.0](v0.8.3...v0.9.0)
(2026-11-27)


### Features

* an option to read csv quotes strictly, refusing what the reader would
otherwise repair
([#199](#199))
([3ba2885](3ba2885))
* group rows into outline levels in the xlsx and ods writers
([#203](#203))
([5b87928](5b87928)),
closes [#197](#197)


### Bug Fixes

* strict csv quoting names where it refuses, stays cancellable and drops
any whitespace around a quoted field
([#202](#202))
([3d4f26b](3d4f26b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Slava <[email protected]>
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 strict quotes: follow-ups from the review of #199

1 participant