diff --git a/CHANGELOG.md b/CHANGELOG.md index 60e873184..d48fe972d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ ## 1.10.0 [unreleased] ### Features -1. [#23](https://github.com/influxdata/influxdb-client-csharp/pull/102): Added WriteApiAsync for asynchronous write without batching +1. [#102](https://github.com/influxdata/influxdb-client-csharp/pull/102): Added WriteApiAsync for asynchronous write without batching + +### Bug Fixes +1. [#106](https://github.com/influxdata/influxdb-client-csharp/pull/106): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol, `=` is valid sign for measurement name ## 1.9.0 [2020-06-19] diff --git a/Client.Test/PointDataTest.cs b/Client.Test/PointDataTest.cs index f3ee0767a..fbb1d9c17 100644 --- a/Client.Test/PointDataTest.cs +++ b/Client.Test/PointDataTest.cs @@ -21,6 +21,28 @@ public void TagEmptyTagValue() Assert.AreEqual("h2o,location=europe level=2i", point.ToLineProtocol()); } + [Test] + public void TagEscapingKeyAndValue() { + + var point = PointData.Measurement("h\n2\ro\t_data") + .Tag("new\nline", "new\nline") + .Tag("carriage\rreturn", "carriage\rreturn") + .Tag("t\tab", "t\tab") + .Field("level", 2); + + Assert.AreEqual("h\\n2\\ro\\t_data,carriage\\rreturn=carriage\\rreturn,new\\nline=new\\nline,t\\tab=t\\tab level=2i", point.ToLineProtocol()); + } + + [Test] + public void EqualSignEscaping() { + + var point = PointData.Measurement("h=2o") + .Tag("l=ocation", "e=urope") + .Field("l=evel", 2); + + Assert.AreEqual("h=2o,l\\=ocation=e\\=urope l\\=evel=2i", point.ToLineProtocol()); + } + [Test] public void Immutability() { @@ -60,7 +82,7 @@ public void MeasurementEscape() .Tag("", "warn") .Field("level", 2); - Assert.AreEqual("h2\\=o,location=europe level=2i", point.ToLineProtocol()); + Assert.AreEqual("h2=o,location=europe level=2i", point.ToLineProtocol()); point = PointData.Measurement("h2,o") .Tag("location", "europe") diff --git a/Client/Writes/PointData.cs b/Client/Writes/PointData.cs index 4d75b60d9..b9a22c0a4 100644 --- a/Client/Writes/PointData.cs +++ b/Client/Writes/PointData.cs @@ -298,7 +298,7 @@ public string ToLineProtocol(PointSettings pointSettings = null) { var sb = new StringBuilder(); - EscapeKey(sb, _measurementName); + EscapeKey(sb, _measurementName, false); AppendTags(sb, pointSettings); var appendedFields = AppendFields(sb); if (!appendedFields) @@ -469,17 +469,32 @@ private void AppendTime(StringBuilder sb) /// /// The sb. /// The key. - private void EscapeKey(StringBuilder sb, string key) + /// Configure to escaping equal. + private void EscapeKey(StringBuilder sb, string key, bool escapeEqual = true) { foreach (var c in key) { switch (c) { + case '\n': + sb.Append("\\n"); + continue; + case '\r': + sb.Append("\\r"); + continue; + case '\t': + sb.Append("\\t"); + continue; case ' ': case ',': - case '=': sb.Append("\\"); break; + case '=': + if (escapeEqual) + { + sb.Append("\\"); + } + break; } sb.Append(c);