Description
The CSVPrinter ecapses new line and return character to "\n" and "\r" if these occur within the encapsulators (this is within the CSVPrinter.escapeAndQuote(String) method). However, the CSVParser do not convert these back to new line and return characters in the same fashion. So if you use the CSVPrinter to create a delimited file containing new line or return characters within an entry and then read this file using the CSVParser the text read in by the CSVParser will not match the text written by the CSVPrinter (the difference being that every new line and return character will be replaced by "\n" and "\r" respectively).
A possible fix for this would be to add two extra 'else if' statements to CSVParser.encapsulatedTokenLexer(Token, int) starting at line 49, as detailed below (the ehampsised text indicated the changes):
else if (c == '
' && in.lookAhead() == '
')
else if (c == '
' && in.lookAhead() == 'n')
{
_ // escaped java new line character, append a new line character_
tkn.content.append('\n');
c = in.read();
}
else if (c == '
' && in.lookAhead() == 'r')
{
// escaped java return character, append a return character
tkn.content.append('\r');
c = in.read();
}
else if (strategy.getUnicodeEscapeInterpretation() && c == '
'
&& in.lookAhead() == 'u')