Skip to content

Commit ca96121

Browse files
author
Dai MIKURUBE
committed
Add InvalidCharacterAfterQuoteException instead of InvalidCsvQuotationException(String.format("Unexpected extra character '%c' after a value quoted by '%c'", ...)
1 parent 52cb52b commit ca96121

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public String nextColumn() {
473473
// column has trailing spaces and quoted. TODO should this be rejected?
474474

475475
} else {
476-
throw new InvalidCsvQuotationException(String.format("Unexpected extra character '%c' after a value quoted by '%c'", c, this.quote));
476+
throw new InvalidCharacterAfterQuoteException(c, this.quote);
477477
}
478478
break;
479479

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2022 The Embulk project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.embulk.parser.csv;
18+
19+
public class InvalidCharacterAfterQuoteException extends InvalidCsvQuotationException {
20+
public InvalidCharacterAfterQuoteException(final char extraChar, final char quoteChar) {
21+
super(String.format("Unexpected extra character '%c' after a quote by '%c'.", extraChar, quoteChar));
22+
this.extraChar = extraChar;
23+
this.quoteChar = quoteChar;
24+
}
25+
26+
private final char extraChar;
27+
private final char quoteChar;
28+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public void throwWithDefaultQuotesInQuotedFields() throws Exception {
300300
parse(builder, "\n", 2, "\"foo\"bar\",\"hoge\"fuga\"");
301301
fail();
302302
} catch (Exception e) {
303-
assertTrue(e instanceof InvalidCsvQuotationException);
304-
assertEquals("Unexpected extra character 'b' after a value quoted by '\"'", e.getMessage());
303+
assertTrue(e instanceof InvalidCharacterAfterQuoteException);
304+
assertEquals("Unexpected extra character 'b' after a quote by '\"'.", e.getMessage());
305305
return;
306306
}
307307
}
@@ -314,8 +314,8 @@ public void throwWithQuotesInQuotedFields_ACCEPT_ONLY_RFC4180_ESCAPED() throws E
314314
parse(builder, "\n", 2, "\"foo\"bar\",\"hoge\"fuga\"");
315315
fail();
316316
} catch (Exception e) {
317-
assertTrue(e instanceof InvalidCsvQuotationException);
318-
assertEquals("Unexpected extra character 'b' after a value quoted by '\"'", e.getMessage());
317+
assertTrue(e instanceof InvalidCharacterAfterQuoteException);
318+
assertEquals("Unexpected extra character 'b' after a quote by '\"'.", e.getMessage());
319319
return;
320320
}
321321
}

0 commit comments

Comments
 (0)