From the CSV spec (RFC 4180), Spaces are considered part of a field and should not be ignored. Obviously if the field contains double quotes it should retain the spaces inside the quotes.
My question is, what about spaces outside of the double quotes? The only way I can see this happening is if the tool that generated the CSV didn’t do it properly.
Example: one, "two" ,three
Should the space before and after "two" be included?
That cell is invalid – to properly code that row it should be:
Double quotes must also be escaped (as double-double quote) since they are used as the escape sequence. If you don’t want to preserve the quotes around
two, technically there are two things invalid about the row – (1) the spaces before and after the quotes and (2) the fact that there are quotes around the cell but nothing to be escaped. CSV demands that there can only be quotes around the cell if there are commas or quotes inside the content of the cell.If I were in your case, I would err on the side of leniency.