Skip to content

Commit d81528f

Browse files
committed
Revert "Add a setting that controls whether the last field on the last line, if quoted, has to have a closing quote before the file ends."
This reverts commit d0ea9e3.
1 parent b1bdb99 commit d81528f

3 files changed

Lines changed: 11 additions & 64 deletions

File tree

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

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ public static Builder create(final CSVFormat csvFormat) {
206206
return new Builder(csvFormat);
207207
}
208208

209-
private boolean allowEofWithoutClosingQuote;
210-
211209
private boolean allowMissingColumnNames;
212210

213211
private boolean allowTrailingText;
@@ -269,7 +267,6 @@ private Builder(final CSVFormat csvFormat) {
269267
this.quotedNullString = csvFormat.quotedNullString;
270268
this.duplicateHeaderMode = csvFormat.duplicateHeaderMode;
271269
this.allowTrailingText = csvFormat.allowTrailingText;
272-
this.allowEofWithoutClosingQuote = csvFormat.allowEofWithoutClosingQuote;
273270
}
274271

275272
/**
@@ -294,19 +291,6 @@ public Builder setAllowDuplicateHeaderNames(final boolean allowDuplicateHeaderNa
294291
return this;
295292
}
296293

297-
/**
298-
* Sets whether the last field on the last line, if quoted, can have no closing quote when the file ends, {@code true} if this is ok,
299-
* {@code false} if {@link IOException} should be thrown.
300-
*
301-
* @param allowEofWithoutClosingQuote whether to allow the last field on the last line to have a missing closing quote when the file ends,
302-
* {@code true} if so, or {@code false} to cause an {@link IOException} to be thrown.
303-
* @since 1.10.0
304-
*/
305-
public Builder setAllowEofWithoutClosingQuote(final boolean allowEofWithoutClosingQuote) {
306-
this.allowEofWithoutClosingQuote = allowEofWithoutClosingQuote;
307-
return this;
308-
}
309-
310294
/**
311295
* Sets the parser missing column names behavior, {@code true} to allow missing column names in the header line, {@code false} to cause an
312296
* {@link IllegalArgumentException} to be thrown.
@@ -843,7 +827,7 @@ public CSVFormat getFormat() {
843827
* @see Predefined#Default
844828
*/
845829
public static final CSVFormat DEFAULT = new CSVFormat(COMMA, DOUBLE_QUOTE_CHAR, null, null, null, false, true, CRLF, null, null, null, false, false, false,
846-
false, false, false, DuplicateHeaderMode.ALLOW_ALL, false, false);
830+
false, false, false, DuplicateHeaderMode.ALLOW_ALL, false);
847831

848832
/**
849833
* Excel file format (using a comma as the value delimiter). Note that the actual value delimiter used by Excel is locale dependent, it might be necessary
@@ -868,7 +852,6 @@ public CSVFormat getFormat() {
868852
* <li>{@code setAllowMissingColumnNames(true)}</li>
869853
* <li>{@code setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL)}</li>
870854
* <li>{@code setAllowTrailingText(true)}</li>
871-
* <li>{@code setAllowEofWithoutClosingQuote(true)}</li>
872855
* </ul>
873856
* <p>
874857
* Note: This is currently like {@link #RFC4180} plus {@link Builder#setAllowMissingColumnNames(boolean) Builder#setAllowMissingColumnNames(true)} and
@@ -882,7 +865,6 @@ public CSVFormat getFormat() {
882865
.setIgnoreEmptyLines(false)
883866
.setAllowMissingColumnNames(true)
884867
.setAllowTrailingText(true)
885-
.setAllowEofWithoutClosingQuote(true)
886868
.build();
887869
// @formatter:on
888870

@@ -1305,7 +1287,7 @@ private static boolean isTrimChar(final CharSequence charSequence, final int pos
13051287
*/
13061288
public static CSVFormat newFormat(final char delimiter) {
13071289
return new CSVFormat(String.valueOf(delimiter), null, null, null, null, false, false, null, null, null, null, false, false, false, false, false, false,
1308-
DuplicateHeaderMode.ALLOW_ALL, false, false);
1290+
DuplicateHeaderMode.ALLOW_ALL, false);
13091291
}
13101292

13111293
static String[] toStringArray(final Object[] values) {
@@ -1347,8 +1329,6 @@ public static CSVFormat valueOf(final String format) {
13471329

13481330
private final DuplicateHeaderMode duplicateHeaderMode;
13491331

1350-
private final boolean allowEofWithoutClosingQuote;
1351-
13521332
private final boolean allowMissingColumnNames;
13531333

13541334
private final boolean allowTrailingText;
@@ -1408,7 +1388,6 @@ private CSVFormat(final Builder builder) {
14081388
this.quotedNullString = builder.quotedNullString;
14091389
this.duplicateHeaderMode = builder.duplicateHeaderMode;
14101390
this.allowTrailingText = builder.allowTrailingText;
1411-
this.allowEofWithoutClosingQuote = builder.allowEofWithoutClosingQuote;
14121391
validate();
14131392
}
14141393

@@ -1439,7 +1418,7 @@ private CSVFormat(final String delimiter, final Character quoteChar, final Quote
14391418
final boolean ignoreSurroundingSpaces, final boolean ignoreEmptyLines, final String recordSeparator, final String nullString,
14401419
final Object[] headerComments, final String[] header, final boolean skipHeaderRecord, final boolean allowMissingColumnNames,
14411420
final boolean ignoreHeaderCase, final boolean trim, final boolean trailingDelimiter, final boolean autoFlush,
1442-
final DuplicateHeaderMode duplicateHeaderMode, final boolean allowTrailingText, final boolean allowEofWithoutClosingQuote) {
1421+
final DuplicateHeaderMode duplicateHeaderMode, final boolean allowTrailingText) {
14431422
this.delimiter = delimiter;
14441423
this.quoteCharacter = quoteChar;
14451424
this.quoteMode = quoteMode;
@@ -1460,7 +1439,6 @@ private CSVFormat(final String delimiter, final Character quoteChar, final Quote
14601439
this.quotedNullString = quoteCharacter + nullString + quoteCharacter;
14611440
this.duplicateHeaderMode = duplicateHeaderMode;
14621441
this.allowTrailingText = allowTrailingText;
1463-
this.allowEofWithoutClosingQuote = allowEofWithoutClosingQuote;
14641442
validate();
14651443
}
14661444

@@ -1515,7 +1493,7 @@ public boolean equals(final Object obj) {
15151493
Objects.equals(nullString, other.nullString) && Objects.equals(quoteCharacter, other.quoteCharacter) && quoteMode == other.quoteMode &&
15161494
Objects.equals(quotedNullString, other.quotedNullString) && Objects.equals(recordSeparator, other.recordSeparator) &&
15171495
skipHeaderRecord == other.skipHeaderRecord && trailingDelimiter == other.trailingDelimiter && trim == other.trim &&
1518-
allowTrailingText == other.allowTrailingText && allowEofWithoutClosingQuote == other.allowEofWithoutClosingQuote;
1496+
allowTrailingText == other.allowTrailingText;
15191497
}
15201498

15211499
/**
@@ -1549,16 +1527,6 @@ public boolean getAllowDuplicateHeaderNames() {
15491527
return duplicateHeaderMode == DuplicateHeaderMode.ALLOW_ALL;
15501528
}
15511529

1552-
/**
1553-
* Gets whether the file can end before the last field on the last line, if quoted, has a closing quote.
1554-
*
1555-
* @return {@code true} if so, {@code false} to throw an {@link IOException}.
1556-
* @since 1.10.0
1557-
*/
1558-
public boolean getAllowEofWithoutClosingQuote() {
1559-
return allowEofWithoutClosingQuote;
1560-
}
1561-
15621530
/**
15631531
* Gets whether missing column names are allowed when parsing the header line.
15641532
*
@@ -1758,9 +1726,9 @@ public int hashCode() {
17581726
int result = 1;
17591727
result = prime * result + Arrays.hashCode(headers);
17601728
result = prime * result + Arrays.hashCode(headerComments);
1761-
return prime * result + Objects.hash(duplicateHeaderMode, allowEofWithoutClosingQuote, allowMissingColumnNames, allowTrailingText,
1762-
autoFlush, commentMarker, delimiter, escapeCharacter, ignoreEmptyLines, ignoreHeaderCase, ignoreSurroundingSpaces,
1763-
nullString, quoteCharacter, quoteMode, quotedNullString, recordSeparator, skipHeaderRecord, trailingDelimiter, trim);
1729+
return prime * result + Objects.hash(duplicateHeaderMode, allowMissingColumnNames, allowTrailingText, autoFlush, commentMarker, delimiter,
1730+
escapeCharacter, ignoreEmptyLines, ignoreHeaderCase, ignoreSurroundingSpaces, nullString, quoteCharacter, quoteMode, quotedNullString,
1731+
recordSeparator, skipHeaderRecord, trailingDelimiter, trim);
17641732
}
17651733

17661734
/**

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ final class Lexer implements Closeable {
5858
private final boolean ignoreSurroundingSpaces;
5959
private final boolean ignoreEmptyLines;
6060
private final boolean allowTrailingText;
61-
private final boolean allowEofWithoutClosingQuote;
6261

6362
/** The input stream */
6463
private final ExtendedBufferedReader reader;
@@ -75,7 +74,6 @@ final class Lexer implements Closeable {
7574
this.ignoreSurroundingSpaces = format.getIgnoreSurroundingSpaces();
7675
this.ignoreEmptyLines = format.getIgnoreEmptyLines();
7776
this.allowTrailingText = format.getAllowTrailingText();
78-
this.allowEofWithoutClosingQuote = format.getAllowEofWithoutClosingQuote();
7977
this.delimiterBuf = new char[delimiter.length - 1];
8078
this.escapeDelimiterBuf = new char[2 * delimiter.length - 1];
8179
}
@@ -380,15 +378,9 @@ private Token parseEncapsulatedToken(final Token token) throws IOException {
380378
}
381379
}
382380
} else if (isEndOfFile(c)) {
383-
if (allowEofWithoutClosingQuote) {
384-
token.type = EOF;
385-
token.isReady = true; // There is data at EOF
386-
return token;
387-
} else {
388-
// error condition (end of file before end of token)
389-
throw new IOException("(startline " + startLineNumber +
390-
") EOF reached before encapsulated token finished");
391-
}
381+
// error condition (end of file before end of token)
382+
throw new IOException("(startline " + startLineNumber +
383+
") EOF reached before encapsulated token finished");
392384
} else {
393385
// consume character
394386
token.content.append((char) c);

src/test/java/org/apache/commons/csv/LexerTest.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,20 +441,7 @@ public void testTrailingTextAfterQuote() throws Exception {
441441
assertThat(parser.nextToken(new Token()), matches(EOF, "a b \"\""));
442442
}
443443
try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setAllowTrailingText(false).build())) {
444-
assertThrows(IOException.class, () -> parser.nextToken(new Token()));
445-
}
446-
}
447-
448-
@Test
449-
public void testEOFWithoutClosingQuote() throws Exception {
450-
final String code = "a,\"b";
451-
try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setAllowEofWithoutClosingQuote(true).build())) {
452-
assertThat(parser.nextToken(new Token()), matches(TOKEN, "a"));
453-
assertThat(parser.nextToken(new Token()), matches(EOF, "b"));
454-
}
455-
try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setAllowEofWithoutClosingQuote(false).build())) {
456-
assertThat(parser.nextToken(new Token()), matches(TOKEN, "a"));
457-
assertThrows(IOException.class, () -> parser.nextToken(new Token()));
444+
assertThrows(IOException.class, () -> lexer.nextToken(new Token()));
458445
}
459446
}
460447
}

0 commit comments

Comments
 (0)