From 8f23758da6b5fa3ef7de46bdafbe77af55a10b66 Mon Sep 17 00:00:00 2001 From: Oliver Rahner Date: Fri, 24 May 2024 11:07:24 +0200 Subject: [PATCH] fix: add escaping for backslashes, fixes #718 --- .../src/main/java/com/influxdb/client/write/Point.java | 3 +++ .../test/java/com/influxdb/client/write/PointTest.java | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/client/src/main/java/com/influxdb/client/write/Point.java b/client/src/main/java/com/influxdb/client/write/Point.java index cc0d38c4d25..d26a3726de7 100644 --- a/client/src/main/java/com/influxdb/client/write/Point.java +++ b/client/src/main/java/com/influxdb/client/write/Point.java @@ -442,6 +442,9 @@ private void escapeKey(@Nonnull final StringBuilder sb, @Nonnull final String ke private void escapeKey(@Nonnull final StringBuilder sb, @Nonnull final String key, final boolean escapeEqual) { for (int i = 0; i < key.length(); i++) { switch (key.charAt(i)) { + case '\\': + sb.append("\\\\"); + continue; case '\n': sb.append("\\n"); continue; diff --git a/client/src/test/java/com/influxdb/client/write/PointTest.java b/client/src/test/java/com/influxdb/client/write/PointTest.java index e93827055e5..b0a421e24b8 100644 --- a/client/src/test/java/com/influxdb/client/write/PointTest.java +++ b/client/src/test/java/com/influxdb/client/write/PointTest.java @@ -182,6 +182,16 @@ void fieldEscape() { Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2o,location=europe level=\"string esc\\\"ape value\""); } + @Test + void tagEscape() { + Point point = Point.measurement("h2o") + .addTag("location", "\\") + .addTag("zone", "europe") + .addField("level", "dummy value"); + + Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2o,location=\\\\,zone=europe level=\"dummy value\""); + } + @Test void time() {