Skip to content

Commit 28acf11

Browse files
committed
CSVFormat does not support explicit " as escape char
1 parent afbeaed commit 28acf11

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<action type="fix" dev="ggregory" due-to="Dávid Szigecsán">Migrate CSVFormat#print(File, Charset) to NIO #445.</action>
5151
<action type="fix" dev="ggregory" due-to="Dávid Szigecsán">Fix documentation for CSVFormat private constructor #466.</action>
5252
<action type="fix" issue="CSV-294" dev="ggregory" due-to="Joern Huxhorn, Gary Gregory">CSVFormat does not support explicit " as escape char.</action>
53+
<action type="fix" issue="CSV-150" dev="ggregory" due-to="dota17, Gary Gregory, Jörn Huxhorn">CSVFormat does not support explicit " as escape char.</action>
5354
<!-- UPDATE -->
5455
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons-codec:commons-codec from 1.16.1 to 1.17.1 #422, #449.</action>
5556
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 69 to 74 #435, #452, #465, #468.</action>

src/main/java/org/apache/commons/csv/Lexer.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,12 @@ final class Lexer implements Closeable {
3232
private static final String CR_STRING = Character.toString(Constants.CR);
3333
private static final String LF_STRING = Character.toString(Constants.LF);
3434

35-
/**
36-
* Constant char to use for disabling comments, escapes, and encapsulation. The value -2 is used because it
37-
* won't be confused with an EOF signal (-1), and because the Unicode value {@code FFFE} would be encoded as two
38-
* chars (using surrogates) and thus there should never be a collision with a real text char.
39-
*/
40-
private static final char DISABLED = '\ufffe';
41-
4235
private final char[] delimiter;
4336
private final char[] delimiterBuf;
4437
private final char[] escapeDelimiterBuf;
45-
private final char escape;
46-
private final char quoteChar;
47-
private final char commentStart;
38+
private final int escape;
39+
private final int quoteChar;
40+
private final int commentStart;
4841
private final boolean ignoreSurroundingSpaces;
4942
private final boolean ignoreEmptyLines;
5043
private final boolean lenientEof;
@@ -197,8 +190,8 @@ boolean isStartOfLine(final int ch) {
197190
return ch == Constants.LF || ch == Constants.CR || ch == Constants.UNDEFINED;
198191
}
199192

200-
private char mapNullToDisabled(final Character c) {
201-
return c == null ? DISABLED : c.charValue(); // N.B. Explicit (un)boxing is intentional
193+
private int mapNullToDisabled(final Character c) {
194+
return c == null ? -1 : c.charValue(); // Explicit unboxing is intentional
202195
}
203196

204197
/**
@@ -512,4 +505,5 @@ void trimTrailingSpaces(final StringBuilder buffer) {
512505
buffer.setLength(length);
513506
}
514507
}
508+
515509
}

src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323

2424
import org.apache.commons.csv.CSVFormat;
2525
import org.apache.commons.csv.CSVParser;
26-
import org.junit.jupiter.api.Disabled;
2726
import org.junit.jupiter.api.Test;
2827

29-
@Disabled
3028
public class JiraCsv150Test {
3129

3230
private void testDisable(final CSVFormat csvFormat, final StringReader stringReader) throws IOException {

0 commit comments

Comments
 (0)