Myth: CSV Is Just Comma-Separated Values
The name says it: comma-separated values. So the parser is one line: split on commas. I tested that belief with a real run, and a single quoted field broke it. Full run in this Short: https://youtu.be/s4W4DtdlBCs
The name says it: comma-separated values. So the parser is one line: split on commas. I tested that belief with a real run, and a single quoted field broke it. Full run in this Short: https://youtu.be/s4W4DtdlBCs
The field that breaks the split
Take a name field like this:
"Smith, Jo"
That is one field containing a comma, wrapped in quotes to protect it. A naive line.split(',') has no notion of quotes, so it returns two fields: "Smith and Jo". Every column after it shifts, and the row is silently corrupt.
The one-flag fix
The fix is a single piece of state: a flag that says whether you are inside quotes. While the flag is on, a comma is plain text, not a delimiter. Walk the field character by character, flip the flag on each unescaped quote, and only treat commas as separators when the flag is off.
That one flag is the entire difference between "CSV is trivial" and a parser that survives real files. It is also why every serious CSV library is a state machine under the hood.
What I did not test
Huge files and encodings other than UTF-8 are still open. For production, use a maintained library. But the myth itself costs nothing to check, and one quoted name is enough to break it.
Watch the run
The real terminal output is in the Short: https://youtu.be/s4W4DtdlBCs (narration is AI-generated; the test output is from a real run).
Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.