You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Benedikt Ritter (JIRA)" <ji...@apache.org> on 2014/08/14 22:08:29 UTC
[jira] [Closed] (CSV-33) The CSVPrinter ecapsing inconsistant with
CSVParser
[ https://issues.apache.org/jira/browse/CSV-33?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Benedikt Ritter closed CSV-33.
------------------------------
> The CSVPrinter ecapsing inconsistant with CSVParser
> ---------------------------------------------------
>
> Key: CSV-33
> URL: https://issues.apache.org/jira/browse/CSV-33
> Project: Commons CSV
> Issue Type: Bug
> Components: Printer
> Reporter: Colin Goodheart-Smithe
> Priority: Minor
> Fix For: 1.0
>
> Attachments: CSVParser.java, CSVPrintTest.java
>
>
> 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() == '\\')
> {
> // doubled escape char, it does not escape itself, only encapsulator
> // -> add both escape chars to stream
> tkn.content.append((char) c);
> c = in.read();
> tkn.content.append((char) c);
> }
> _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')
> {
> // interpret unicode escaped chars (like \u0070 -> p)
> tkn.content.append((char) unicodeEscapeLexer(c));
> }
--
This message was sent by Atlassian JIRA
(v6.2#6252)