Repository navigation
Conversation
Signed-off-by: Inf1mum <vadim.lazuk@mail.ru>
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 CSV-331 —
CSVFormatignorestrimwhen printing aReadervalue.Problem
The Javadoc of
CSVFormat.print(Object, Appendable, boolean)promises that the value is trimmed whengetTrim()is true, but aReadervalue took an early-return branch into the streamingprint(Reader, ...)path, which cannot applytrim(CharSequence). As a result, aReadervalue was printed untrimmed:Change
In
print(Object, Appendable, boolean), when the value is aReaderand trimming is enabled, the reader is fully read into memory (IOUtils.toString(Reader)) and the value then goes through the regular CharSequence path where the existingtrim(CharSequence)helper and quoting/escaping logic apply. When trimming is disabled, the behavior is unchanged: the value is streamed as before without holding it in memory.print(Object, Appendable, boolean)now documents the in-memory buffering whentrimis true, and the privateprint(Reader, ...)documents that trimming is handled by the caller.Testing
testTrimReaderValue(includes the CSV-331 reproduction withCSVFormat.ORACLE),testTrimReaderValueWithQuotes(a trimmed Reader value that needs encapsulation is still quoted correctly), andtestNoTrimReaderValue(streaming path unchanged without trim).CSVFormatTestandCSVPrinterTest: 287 tests, 0 failures.Note: when
trimis true aReadervalue is buffered fully in memory (documented in the Javadoc). This keeps the memory-free streaming guarantee only for the untrimmed case, matching what is possible without changing the streamingprintWithQuotes(Reader)/printWithEscapes(Reader)implementations.