Skip to content

Commit 3324468

Browse files
author
Dai MIKURUBE
committed
Validate QuotedFieldLengthLimitExceededException
1 parent 2acb79c commit 3324468

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

embulk-parser-csv/src/main/java/org/embulk/parser/csv/CsvTokenizer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public String nextColumn() {
423423
// A non-escaped stray "quote character" in the field is processed as a regular character
424424
// if ACCEPT_STRAY_QUOTES_ASSUMING_NO_DELIMITERS_IN_FIELDS is specified,
425425
if ((this.linePos - valueStartPos) + quotedValue.length() > this.maxQuotedFieldLength) {
426-
throw new QuotedSizeLimitExceededException("The size of the quoted value exceeds the limit size (" + this.maxQuotedFieldLength + ")");
426+
throw new QuotedFieldLengthLimitExceededException(this.maxQuotedFieldLength);
427427
}
428428
} else {
429429
quotedValue.append(this.line.substring(valueStartPos, this.linePos - 1));
@@ -449,7 +449,7 @@ public String nextColumn() {
449449

450450
} else {
451451
if ((this.linePos - valueStartPos) + quotedValue.length() > this.maxQuotedFieldLength) {
452-
throw new QuotedSizeLimitExceededException("The size of the quoted value exceeds the limit size (" + this.maxQuotedFieldLength + ")");
452+
throw new QuotedFieldLengthLimitExceededException(this.maxQuotedFieldLength);
453453
}
454454
// keep QUOTED_VALUE state
455455
}

embulk-parser-csv/src/main/java/org/embulk/parser/csv/QuotedFieldLengthLimitExceededException.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package org.embulk.parser.csv;
1818

19-
public class QuotedSizeLimitExceededException extends InvalidCsvQuotationException {
20-
public QuotedSizeLimitExceededException(final String message) {
21-
super(message);
19+
public class QuotedFieldLengthLimitExceededException extends InvalidCsvQuotationException {
20+
public QuotedFieldLengthLimitExceededException(final long quotedFieldLengthLimit) {
21+
super("The length of the quoted field exceeds the limit (" + quotedFieldLengthLimit + ")");
22+
this.quotedFieldLengthLimit = quotedFieldLengthLimit;
2223
}
24+
25+
private final long quotedFieldLengthLimit;
2326
}

embulk-parser-csv/src/test/java/org/embulk/parser/csv/TestCsvTokenizer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ public void parseWithQuotesInQuotedFields_ACCEPT_STRAY_QUOTES_ASSUMING_NO_DELIMI
338338
}
339339

340340
@Test
341-
public void throwQuotedSizeLimitExceededException() throws Exception {
341+
public void throwQuotedFieldLengthLimitExceededException() throws Exception {
342342
final CsvTokenizer.Builder builder = initialBuilder();
343343
builder.setMaxQuotedFieldLength(8);
344344

@@ -348,7 +348,7 @@ public void throwQuotedSizeLimitExceededException() throws Exception {
348348
"v3,\"0123456789\"");
349349
fail();
350350
} catch (Exception e) {
351-
assertTrue(e instanceof QuotedSizeLimitExceededException);
351+
assertTrue(e instanceof QuotedFieldLengthLimitExceededException);
352352
}
353353

354354
// multi-line
@@ -358,12 +358,12 @@ public void throwQuotedSizeLimitExceededException() throws Exception {
358358
"\"012345\n6789\",v3");
359359
fail();
360360
} catch (Exception e) {
361-
assertTrue(e instanceof QuotedSizeLimitExceededException);
361+
assertTrue(e instanceof QuotedFieldLengthLimitExceededException);
362362
}
363363
}
364364

365365
@Test
366-
public void recoverFromQuotedSizeLimitExceededException() throws Exception {
366+
public void recoverFromQuotedFieldLengthLimitExceededException() throws Exception {
367367
final CsvTokenizer.Builder builder = initialBuilder();
368368
builder.setMaxQuotedFieldLength(12);
369369

@@ -388,7 +388,7 @@ public void recoverFromQuotedSizeLimitExceededException() throws Exception {
388388
tokenizer.nextColumn();
389389
fail();
390390
} catch (Exception e) {
391-
assertTrue(e instanceof QuotedSizeLimitExceededException);
391+
assertTrue(e instanceof QuotedFieldLengthLimitExceededException);
392392
}
393393
assertEquals("v3,\"0123", tokenizer.skipCurrentLine());
394394

0 commit comments

Comments
 (0)