Skip to content

Commit ca1ed20

Browse files
committed
[CSV-150] Escaping is not disableable
1 parent 0546fb5 commit ca1ed20

3 files changed

Lines changed: 10 additions & 17 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">Escaping is not disableable.</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: 9 additions & 16 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;
@@ -59,9 +52,9 @@ final class Lexer implements Closeable {
5952
Lexer(final CSVFormat format, final ExtendedBufferedReader reader) {
6053
this.reader = reader;
6154
this.delimiter = format.getDelimiterCharArray();
62-
this.escape = mapNullToDisabled(format.getEscapeCharacter());
63-
this.quoteChar = mapNullToDisabled(format.getQuoteCharacter());
64-
this.commentStart = mapNullToDisabled(format.getCommentMarker());
55+
this.escape = nullToDisabled(format.getEscapeCharacter());
56+
this.quoteChar = nullToDisabled(format.getQuoteCharacter());
57+
this.commentStart = nullToDisabled(format.getCommentMarker());
6558
this.ignoreSurroundingSpaces = format.getIgnoreSurroundingSpaces();
6659
this.ignoreEmptyLines = format.getIgnoreEmptyLines();
6760
this.lenientEof = format.getLenientEof();
@@ -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 nullToDisabled(final Character c) {
194+
return c == null ? Constants.UNDEFINED : c.charValue(); // Explicit unboxing
202195
}
203196

204197
/**
@@ -428,7 +421,7 @@ private void appendNextEscapedCharacterToToken(final Token token) throws IOExcep
428421
} else {
429422
final int unescaped = readEscape();
430423
if (unescaped == EOF) { // unexpected char after escape
431-
token.content.append(escape).append((char) reader.getLastChar());
424+
token.content.append((char) escape).append((char) reader.getLastChar());
432425
} else {
433426
token.content.append((char) unescaped);
434427
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.junit.jupiter.api.Disabled;
2727
import org.junit.jupiter.api.Test;
2828

29-
@Disabled
3029
public class JiraCsv150Test {
3130

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

0 commit comments

Comments
 (0)