Round-trip CSV exports that contain line breaks, commas or quotes - #154
Merged
Merged
Conversation
Export quoted only Description and KnownPaths, and Import read the file with File.ReadAllLines, so a multi-paragraph description was truncated at its first line break and a suggested name containing a comma dropped the whole row. Export now quotes every field, and Import parses the whole file as RFC 4180 records, so quoted fields may span lines. Skipped-row messages still report the line the record starts on. Fixes #149 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0113g7mUxeizhTrH6na279Ez
A double quote is not a valid Windows file-name character, so FileName rejected the test's own fixture on the Windows leg. The name keeps the comma and gains an apostrophe; quote escaping is still covered by the description. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0113g7mUxeizhTrH6na279Ez
SonarCloud flagged ParseCsvRecords for cognitive complexity (17, limit 15) and for advancing the for-loop counter inside the body. Reading a quoted field now lives in ReadQuotedField, and the scan is a while loop. Behaviour is unchanged. Also switch the new tests to Assert.HasCount and Assert.AreSequenceEqual, as the MSTest analyzers suggest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0113g7mUxeizhTrH6na279Ez
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #149
Summary
Export and Import disagreed on the CSV format. Export quoted only
DescriptionandKnownPaths, and Import read the file withFile.ReadAllLines. A multi-paragraph description was cut off at its first line break, and a suggested name likedog, cat.jpgdropped the whole row.BuildCsv(extracted fromExportCsv) quotes and escapes every field. It formats dates and sizes with the invariant culture.ParseCsv(extracted fromImportCsv) reads the whole text through a new RFC 4180ParseCsvRecords, so quoted fields can hold commas, doubled quotes and line breaks. "Skipping line N" messages still name the line each record starts on, and blank lines are still ignored.ParseCsvLinekeeps its signature and existing behaviour; it now delegates to the record parser.Files exported by earlier versions still import: bare fields parse as before.
Test
CsvExportThenImportRoundTripsEveryFieldrunsBuildCsvthenParseCsvon three entries: a multi-paragraph description with doubled quotes, a suggested name with a comma and an apostrophe plus a CRLF description, and multiple known paths. It checks every field. (The suggested name avoids", which Windows doesn't allow in file names; quote escaping is covered by the description.)ParseCsvRecordsKeepsLineBreaksInsideQuotedFieldscovers CRLF, blank lines, embedded newlines, escaped quotes and start-line numbers.With the old export quoting and line-by-line import restored, the round-trip test fails (3 entries in, fewer out). With the fix, the full suite passes 39/39.
This branch also merges cleanly with #152 and #153.
🤖 Generated with Claude Code
https://claude.ai/code/session_0113g7mUxeizhTrH6na279Ez