Skip to content

csv strict quotes: follow-ups from the review of #199 #201

Done

Description

@vaceslav

Follow-up to #198 / #199 (CsvQuoteMode.Strict). None of these blocked the merge; they are what the two reviews of #199 left open.

Errors

  • A stray opening quote in a large file is refused as a limit, not as quoting. In strict mode an opening quote that is never closed reads on until MaxFieldChars (16 M chars by default) and ends as TabularLimitException (limit.exceeded), saying nothing about quoting or where the field began. A small file reaches its end first and gets format.corrupt naming the row, which is what a caller of strict mode wants in both cases. Either refuse it as format.corrupt naming the row the field opened on, or document it on CsvQuoteMode.Strict and in docs/formats.md.
  • A strict refusal inside a zip or tar does not name the entry. The message says The csv file is not valid at row N, and the whole archive fails; naming the entry (the sheet's Source) would tell the caller which file is at fault.
  • format.corrupt vs format.truncated for a file that ends inside a quoted field. corrupt is documented and defensible (a forgotten quote is not a clipped upload), but decide it deliberately.

Bounds and cancellation

  • The blank skip after a closing quote is unbounded and not cancellable. EndQuotedFieldStrictly skips whitespace in a loop that neither counts towards sinceCheck nor is bounded: "x" followed by 300 M spaces is linear and allocates nothing, but a token cancelled 50 ms in took effect only after the run (~0.4 s). Count the skipped characters into the cancellation stride or bound the run by MaxFieldChars.
  • Dropped leading blanks still count against MaxFieldChars. With MaxFieldChars = 8, ten spaces and "x" throw limit.exceeded although the value is x. Either don't count them or document it.

Speed (strict mode only)

  • The quoted fast path still stops at every delimiter and line break inside a quoted field, because it searches for the same specials as the repair mode needs. A strict-only SearchValues holding just the quote would read long quoted text in one run. The default path is unaffected.

Tests and small fixes

  • No test reads a csv entry of a zip or tar archive strictly (only gzip is covered).
  • No named test puts a strict refusal, or blanks before an opening quote, exactly on the 64 KB read-buffer boundary (the reviewer's fuzz covered it and found nothing).
  • The comment in StrictQuoteTests.ReadsQuotesAfterLeadingBlanksInLinearTime estimates the quadratic case at "some fifteen seconds" for 60,000 quotes; it was measured at 24 s.
  • Quote = ' ' (or tab with another delimiter) together with Strict makes the quote character also a blank. It reads sensibly in what was tried, but the options neither refuse nor document the combination.
  • Only space and tab are dropped around a quoted field; a non-breaking space (common in text pasted from spreadsheets) is not, so "x,y" with an NBSP in front is split at its comma. As specified, but worth a sentence in the CsvQuoteMode.Strict remarks, or widening the blank set.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions