You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/09/14 19:20:42 UTC
(commons-csv) branch master updated: [CSV-150] Escaping is not disableable
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push:
new ca1ed202 [CSV-150] Escaping is not disableable
ca1ed202 is described below
commit ca1ed20288dc7cf50f0c3f9a97ea2a60d0cd7c0a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Sep 14 15:20:36 2024 -0400
[CSV-150] Escaping is not disableable
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/csv/Lexer.java | 25 ++++++++--------------
.../apache/commons/csv/issues/JiraCsv150Test.java | 1 -
3 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 946c6689..fa5605ea 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -50,6 +50,7 @@
<action type="fix" dev="ggregory" due-to="Dávid Szigecsán">Migrate CSVFormat#print(File, Charset) to NIO #445.</action>
<action type="fix" dev="ggregory" due-to="Dávid Szigecsán">Fix documentation for CSVFormat private constructor #466.</action>
<action type="fix" issue="CSV-294" dev="ggregory" due-to="Joern Huxhorn, Gary Gregory">CSVFormat does not support explicit " as escape char.</action>
+ <action type="fix" issue="CSV-150" dev="ggregory" due-to="dota17, Gary Gregory, Jörn Huxhorn">Escaping is not disableable.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons-codec:commons-codec from 1.16.1 to 1.17.1 #422, #449.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 69 to 74 #435, #452, #465, #468.</action>
diff --git a/src/main/java/org/apache/commons/csv/Lexer.java b/src/main/java/org/apache/commons/csv/Lexer.java
index e2aec718..f33bd77a 100644
--- a/src/main/java/org/apache/commons/csv/Lexer.java
+++ b/src/main/java/org/apache/commons/csv/Lexer.java
@@ -32,19 +32,12 @@ final class Lexer implements Closeable {
private static final String CR_STRING = Character.toString(Constants.CR);
private static final String LF_STRING = Character.toString(Constants.LF);
- /**
- * Constant char to use for disabling comments, escapes, and encapsulation. The value -2 is used because it
- * won't be confused with an EOF signal (-1), and because the Unicode value {@code FFFE} would be encoded as two
- * chars (using surrogates) and thus there should never be a collision with a real text char.
- */
- private static final char DISABLED = '\ufffe';
-
private final char[] delimiter;
private final char[] delimiterBuf;
private final char[] escapeDelimiterBuf;
- private final char escape;
- private final char quoteChar;
- private final char commentStart;
+ private final int escape;
+ private final int quoteChar;
+ private final int commentStart;
private final boolean ignoreSurroundingSpaces;
private final boolean ignoreEmptyLines;
private final boolean lenientEof;
@@ -59,9 +52,9 @@ final class Lexer implements Closeable {
Lexer(final CSVFormat format, final ExtendedBufferedReader reader) {
this.reader = reader;
this.delimiter = format.getDelimiterCharArray();
- this.escape = mapNullToDisabled(format.getEscapeCharacter());
- this.quoteChar = mapNullToDisabled(format.getQuoteCharacter());
- this.commentStart = mapNullToDisabled(format.getCommentMarker());
+ this.escape = nullToDisabled(format.getEscapeCharacter());
+ this.quoteChar = nullToDisabled(format.getQuoteCharacter());
+ this.commentStart = nullToDisabled(format.getCommentMarker());
this.ignoreSurroundingSpaces = format.getIgnoreSurroundingSpaces();
this.ignoreEmptyLines = format.getIgnoreEmptyLines();
this.lenientEof = format.getLenientEof();
@@ -197,8 +190,8 @@ final class Lexer implements Closeable {
return ch == Constants.LF || ch == Constants.CR || ch == Constants.UNDEFINED;
}
- private char mapNullToDisabled(final Character c) {
- return c == null ? DISABLED : c.charValue(); // N.B. Explicit (un)boxing is intentional
+ private int nullToDisabled(final Character c) {
+ return c == null ? Constants.UNDEFINED : c.charValue(); // Explicit unboxing
}
/**
@@ -428,7 +421,7 @@ final class Lexer implements Closeable {
} else {
final int unescaped = readEscape();
if (unescaped == EOF) { // unexpected char after escape
- token.content.append(escape).append((char) reader.getLastChar());
+ token.content.append((char) escape).append((char) reader.getLastChar());
} else {
token.content.append((char) unescaped);
}
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java
index 415fe296..c4575cee 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java
@@ -26,7 +26,6 @@ import org.apache.commons.csv.CSVParser;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
-@Disabled
public class JiraCsv150Test {
private void testDisable(final CSVFormat csvFormat, final StringReader stringReader) throws IOException {