Skip to content

Commit

Permalink
Merge pull request patrickfav#24 from selectAll/fix/npe-on-csv-export
Browse files Browse the repository at this point in the history
Fix: NPE on CSV export
  • Loading branch information
patrickfav authored Jun 20, 2023
2 parents a424705 + 93bd829 commit 3ba88b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public void export(List<Message> messages, OutputStream outputStream) {
writer = new BufferedWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));

for (Message normalizedMessage : messages) {
String message = normalizedMessage.getMessage();
message = message == null ? "" : message.replaceAll("\"", "\\\\\"");
writer.write("\"" + normalizedMessage.getTimestamp().getEpochSecond() + "\"," +
"\"" + normalizedMessage.getChannel() + "\"," +
"\"" + normalizedMessage.getUsername() + "\"," +
"\"" + normalizedMessage.getMessage().replaceAll("\"", "\\\\\"") + "\"" +
"\"" + message + "\"" +
"\n");
}
writer.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public void export() {
exportFormat.export(
List.of(
new Message("m1", "u1", "c1", EPOCH),
new Message("m2", "u2", "c3", EPOCH.plusSeconds(1))
new Message("m2", "u2", "c3", EPOCH.plusSeconds(1)),
new Message(null, "u3", "c3", EPOCH)
),
bout);

String out = bout.toString();

assertEquals("\"0\",\"c1\",\"u1\",\"m1\"\n" +
"\"1\",\"c3\",\"u2\",\"m2\"\n", out);
"\"1\",\"c3\",\"u2\",\"m2\"\n" +
"\"0\",\"c3\",\"u3\",\"\"\n", out);
}
}

0 comments on commit 3ba88b0

Please sign in to comment.