Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Feat: Quote- and Escape-Char for Export-CSV #267

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private void processCsvUploadBatchRecursion(List<Cancellation> cancellations) {

StringWriter stringWriter = new StringWriter();
CSVWriter csvWriter =
new CSVWriter(stringWriter, '\t', CSVWriter.NO_QUOTE_CHARACTER,
CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END);
new CSVWriter(stringWriter, '\t', CSVWriter.DEFAULT_QUOTE_CHARACTER,
'\\', CSVWriter.DEFAULT_LINE_END);
StatefulBeanToCsv<ArchiveCipherDtoV1> beanToCsv =
new StatefulBeanToCsvBuilder<ArchiveCipherDtoV1>(csvWriter)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.CSVWriter;
import com.opencsv.exceptions.CsvException;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -132,7 +133,9 @@ void testCsvExport(int n) throws IOException, NoSuchAlgorithmException, CsvExcep
Assertions.assertEquals(getHash(csvBytes), cancellation.getCsvHash());

CSVParser csvParser = new CSVParserBuilder()
.withEscapeChar('\\')
.withSeparator('\t')
.withQuoteChar(CSVWriter.DEFAULT_QUOTE_CHARACTER)
.build();

try (CSVReader csvReader = new CSVReaderBuilder(new StringReader(csv))
Expand Down Expand Up @@ -161,17 +164,17 @@ private QuickTestArchive buildQuickTestArchive(String tenantId) {
qta.setConfirmationCwa(Boolean.TRUE);
qta.setTestResult(Short.valueOf("6"));
qta.setPrivacyAgreement(Boolean.TRUE);
qta.setLastName("last_name");
qta.setFirstName("first_name");
qta.setLastName("last\n_na\"me");
qta.setFirstName("fir\rst_name");
qta.setEmail("email");
qta.setPhoneNumber("phone_number");
qta.setSex(Sex.MALE);
qta.setStreet("street");
qta.setHouseNumber("house_number");
qta.setZipCode("zip_code");
qta.setCity("city");
qta.setCity("Düßeldorf");
qta.setTestBrandId("test_brand_id");
qta.setTestBrandName("test_brand_name, Ltd, another_part_of_test_brand_name");
qta.setTestBrandName("test_brand_name, \"Ltd\", another_part_of_test_brand_name");
qta.setBirthday("2000-01-01");
qta.setPdf("PDF".getBytes());
qta.setTestResultServerHash("test_result_server_hash");
Expand Down