Normalize CSV output to remove trailing commas and EOF newline #1175
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.
There are two related issues with the CSV export that will trip up CSV parsing. If we create a new project, create a new intgrid layer and draw an X shape into it, the resulting CSV is
The first issue is the trailing commas, which is unusual. This can cause issue parsing. The trailing comma represents each line has a last field of
nullorNone. Some CSV parsing libraries can work around this, and it appears Excel and LibreOffice seem to ignore the empty last column. However if you just split or tokenize the line on the comma, as what most simple parsers would do, you end up with a null final element in the row.The confounding second issue is the trailing commas are inconsistent, as the last line does not have the trailing comma. This thwarts attempts to either preprocess the file by stripping the trailing commas or expect each line to end with null while parsing.
What is perplexing is this looks intentional? The code as written intentionally adds the comma at the end of the row unless the index of the row is the last row, where it does not add the comma.
This changes the CSV output to look like what most people expect: no trailing commas on any row. Also removes the new line at the end of the file though that's neither here nor there. The resulting CSV is
This will however also likely break any tools which expect the odd imbalanced trailing comma behavior.