Splitting CSV by commas or physical lines fails as soon as a cell contains punctuation or a line break. Correct parsing depends on state: the parser must know whether it is at a field boundary, inside an unquoted field, inside a quoted field or immediately after the closing quote. Each state permits a different next character.

Open quotes only at the field boundary

A double quote starts quoted mode only when no unquoted character has already entered the field. This makes the grammar deterministic: a quote appearing later in an unquoted value is an error rather than a hint to rewrite the value. Spaces before an opening quote are data, not ignorable decoration, because CSVBridge deliberately does not trim or repair cells.

Represent one literal quote with two quotes

Inside a quoted field, two adjacent double quotes decode to one literal double quote. A single double quote closes the field. After that closing quote, only the selected delimiter, a record ending or end of input is valid. Rejecting other characters prevents ambiguous mixtures such as a quoted prefix followed by an unquoted suffix from being accepted silently.

Preserve line endings inside the quoted value

A CRLF, LF or CR encountered while quoted is cell content, not a new table record. CSVBridge preserves the exact code units and JSON.stringify escapes them in the result. The record count therefore follows logical records rather than physical lines. An unclosed quoted field at end of input is rejected with no partial JSON left visible.