Skip to content
This repository was archived by the owner on Jul 18, 2023. It is now read-only.

Fix LineProtocolSyntax backslash escaping #87

Closed
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
2 changes: 1 addition & 1 deletion src/InfluxDB.LineProtocol/Payload/LineProtocolSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static string FormatBoolean(object b)

static string FormatString(string s)
{
return "\"" + s.Replace("\"", "\\\"") + "\"";
return "\"" + s.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"";
}

public static string FormatTimestamp(DateTime utcTimestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace InfluxDB.LineProtocol.Tests
{
public class LineProtcolPointTests
public class LineProtocolPointTests
{
[Fact]
public void CompleteExampleFromDocs()
Expand Down Expand Up @@ -54,5 +54,31 @@ public void WriteNanosecondTimestamps()

Assert.Equal(expected, sw.ToString());
}

[Fact]
public void ExampleWithJsonTextWithNestedDoubleQuote()
{
const string expected = "\"measurement\\ with\\ json\\ with\\ quotes\",symbol=test field_key=\"{\\\"content\\\":\\\"test \\\\\\\" data\\\"}\" 1441756800000000000";

var json = "{\"content\":\"test \\\" data\"}";

var point = new LineProtocolPoint(
"\"measurement with json with quotes\"",
new Dictionary<string, object>
{
{ "field_key", json }
},
new Dictionary<string, string>
{
{ "symbol", "test" }
},
new DateTime(2015, 9, 9, 0, 0, 0, DateTimeKind.Utc));

var sw = new StringWriter();
point.Format(sw);

Assert.Equal(expected, sw.ToString());
}

}
}