Skip to content

Commit 0546fb5

Browse files
committed
Revert "CSVFormat does not support explicit " as escape char"
This reverts commit 28acf11.
1 parent 4d07845 commit 0546fb5

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/changes/changes.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
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">Escaping is not disableable.</action>
5453
<!-- UPDATE -->
5554
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons-codec:commons-codec from 1.16.1 to 1.17.1 #422, #449.</action>
5655
<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: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ 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+
3542
private final char[] delimiter;
3643
private final char[] delimiterBuf;
3744
private final char[] escapeDelimiterBuf;
38-
private final int escape;
39-
private final int quoteChar;
40-
private final int commentStart;
45+
private final char escape;
46+
private final char quoteChar;
47+
private final char commentStart;
4148
private final boolean ignoreSurroundingSpaces;
4249
private final boolean ignoreEmptyLines;
4350
private final boolean lenientEof;
@@ -190,8 +197,8 @@ boolean isStartOfLine(final int ch) {
190197
return ch == Constants.LF || ch == Constants.CR || ch == Constants.UNDEFINED;
191198
}
192199

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

197204
/**
@@ -505,5 +512,4 @@ void trimTrailingSpaces(final StringBuilder buffer) {
505512
buffer.setLength(length);
506513
}
507514
}
508-
509515
}

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

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

2424
import org.apache.commons.csv.CSVFormat;
2525
import org.apache.commons.csv.CSVParser;
26+
import org.junit.jupiter.api.Disabled;
2627
import org.junit.jupiter.api.Test;
2728

29+
@Disabled
2830
public class JiraCsv150Test {
2931

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

0 commit comments

Comments
 (0)