Skip to content

Commit 0978071

Browse files
committed
fix: serialization of \n, \r and \t to Line Protocol
1 parent 5ddf643 commit 0978071

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
### Features
44
1. [#112](https://github.com/influxdata/influxdb-client-python/pull/113): Support timestamp with different timezone in _convert_timestamp
55

6+
### Bug Fixes
7+
1. [#115](https://github.com/influxdata/influxdb-client-python/pull/115): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol
8+
69
## 1.8.0 [2020-06-19]
710

811
### Features

influxdb_client/client/write/point.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
EPOCH = UTC.localize(datetime.utcfromtimestamp(0))
1414
DEFAULT_WRITE_PRECISION = WritePrecision.NS
15-
_ESCAPE_KEY = str.maketrans({'\\': '\\\\', ',': r'\,', ' ': r'\ ', '=': r'\=', '\n': ''})
15+
_ESCAPE_KEY = str.maketrans({'\\': '\\\\', ',': r'\,', ' ': r'\ ', '=': r'\=', '\n': '\\n', '\t': '\\t', '\r': '\\r'})
1616
_ESCAPE_STRING = str.maketrans({'\"': r"\"", "\\": r"\\"})
1717

1818

tests/test_point.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ def test_TagEmptyValue(self):
3636

3737
self.assertEqual("h2o,location=europe level=2i", point.to_line_protocol())
3838

39+
def test_TagEscapingKeyAndValue(self):
40+
41+
point = Point.measurement("h\n2\ro\t_data") \
42+
.tag("new\nline", "new\nline") \
43+
.tag("carriage\rreturn", "carriage\nreturn") \
44+
.tag("t\tab", "t\tab") \
45+
.field("level", 2)
46+
47+
self.assertEqual("h\\n2\\ro\\t_data,carriage\\rreturn=carriage\\nreturn,new\\nline=new\\nline,t\\tab=t\\tab level=2i", point.to_line_protocol())
48+
3949
def test_OverrideTagField(self):
4050
point = Point.measurement("h2o") \
4151
.tag("location", "europe") \

0 commit comments

Comments
 (0)