Escape Newlines in Events for Spanner
Newlines were not being escaped in the Spanner implementation,
leading to events causing an Invalid JSON String error when
received by GerritMissedEventsPlaybackManager in the
gerrit-trigger Jenkins plugin.
Change-Id: Ic6e5777e6e5f053963debd24c9ebfef859eceb7d
diff --git a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
index f422cbd..6885d44 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
@@ -132,6 +132,14 @@
* @throws SQLException If there was a problem with the database
*/
void storeEvent(String projectName, Instant timestamp, String event) throws SQLException {
+ switch (databaseDialect) {
+ case SPANNER:
+ if (event != null) {
+ event = event.replace("\\n", "\\\\n");
+ }
+ break;
+ default:
+ }
String values = format("VALUES('%s', '%s', '%s')", projectName, timestamp, event);
execute(
format("INSERT INTO %s(%s, %s, %s) ", TABLE_NAME, PROJECT_ENTRY, DATE_ENTRY, EVENT_ENTRY)