Apache Nutch is an extensible and scalable web crawler
NUTCH-2790 indexer-csv: escape field leading quote character
Patrick Mezard6fa02ef511a1
diff --git a/src/plugin/indexer-csv/src/java/org/apache/nutch/indexwriter/csv/CSVIndexWriter.java b/src/plugin/indexer-csv/src/java/org/apache/nutch/indexwriter/csv/CSVIndexWriter.javaindex 160d03dc1..99c070229 100644--- a/src/plugin/indexer-csv/src/java/org/apache/nutch/indexwriter/csv/CSVIndexWriter.java+++ b/src/plugin/indexer-csv/src/java/org/apache/nutch/indexwriter/csv/CSVIndexWriter.java@@ -405,13 +405,12 @@ public class CSVIndexWriter implements IndexWriter {if (max > maxFieldLength) {max = maxFieldLength;}- while (nextQuoteChar > 0 && nextQuoteChar < max) {+ while (nextQuoteChar >= 0 && nextQuoteChar < max) {csvout.write(value.substring(start, nextQuoteChar).getBytes(encoding));csvout.write(escapeCharacter.bytes);csvout.write(quoteCharacter.bytes);start = nextQuoteChar + 1;nextQuoteChar = quoteCharacter.find(value, start);- if (nextQuoteChar > max) break;}csvout.write(value.substring(start, max).getBytes(encoding));}diff --git a/src/plugin/indexer-csv/src/test/org/apache/nutch/indexwriter/csv/TestCSVIndexWriter.java b/src/plugin/indexer-csv/src/test/org/apache/nutch/indexwriter/csv/TestCSVIndexWriter.javaindex 761d042df..5714cc235 100644--- a/src/plugin/indexer-csv/src/test/org/apache/nutch/indexwriter/csv/TestCSVIndexWriter.java+++ b/src/plugin/indexer-csv/src/test/org/apache/nutch/indexwriter/csv/TestCSVIndexWriter.java@@ -158,6 +158,15 @@ public class TestCSVIndexWriter {"\"a,b:\"\"quote\"\",c\"", csv.trim());}+ @Test+ public void testCSVescapeLeadingQuotes() throws IOException {+ String[] params = { CSVConstants.CSV_FIELDS, "test" };+ String[] fields = { "test", "\"quote\"" };+ String csv = getCSV(params, fields);+ assertEquals("Leading quotes inside a quoted field must be escaped",+ "\"\"\"quote\"\"\"", csv.trim());+ }+@Testpublic void testCSVclipMaxLength() throws IOException {String[] params = { CSVConstants.CSV_FIELDS, "test",