Quote value starting with comment marker in minimal quote mode#610
Conversation
garydgregory
left a comment
There was a problem hiding this comment.
Hello @rootvector2
Thank you for the PR.
Would you please update the new test to make sure that comments are properly printed. We want to make sure the new test shows the difference between printing a comment and printing a value that happens to start with the comment char.
Can you think of other cases to test?
|
Done. The test now prints a real comment with Added a couple more cases too: the marker past the first character ( |
garydgregory
left a comment
There was a problem hiding this comment.
@rootvector2
Please don't bother pushing to github until you've run mvn by itself to run and fix all build failures 🦺
4718744 to
3c2291c
Compare
|
My fault. It was checkstyle |
Extract to local variable.
printWithQuotes(the defaultMINIMALquote mode) decides whether to encapsulate a value by special-casing only the hard-coded#(Constants.COMMENT) as the first character, so a configured comment marker greater than#such as;is left unquoted. I hit this round-tripping printer output back through the parser:CSVFormat.DEFAULT.builder().setCommentMarker(';').get()prints";id", "name"as;id,name, and re-parsing with that same format reads the line as a comment and silently drops the whole record.The encapsulation check is the right place to fix it, since that is already where the printer protects the default comment char, the delimiter, the quote and newlines. The change quotes a value whenever its first character equals the configured comment marker, so the output reads back as data.
mvn; that'smvnon the command line by itself.