From bdb5842eefc24b52286fa9c1cfe1871a93d30f44 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Sun, 14 Oct 2012 23:22:17 +0000 Subject: [PATCH] Validation fails if no quotes mode set but no escape character is set. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1398148 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/csv/CSVFormat.java | 4 ++++ src/test/java/org/apache/commons/csv/CSVFormatTest.java | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index a08b6c8a..7c7097fd 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -199,6 +199,10 @@ public class CSVFormat implements Serializable { if (escape != null && escape == commentStart) { throw new IllegalStateException("The comment start and the escape character cannot be the same ('" + commentStart + "')"); } + + if (escape == null && quotePolicy == Quote.NONE) { + throw new IllegalStateException("No quotes mode set but no escape character is set"); + } } /** diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index b0ba045a..f6884c19 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -153,7 +153,14 @@ public class CSVFormatTest { } catch (final IllegalStateException e) { // expected } - } + + try { + format.withQuoteChar('!').withQuotePolicy(Quote.NONE).validate(); + fail(); + } catch (final IllegalStateException e) { + // expected + } +} @SuppressWarnings("boxing") // no need to worry about boxing here @Test