Skip to content

Commit

Permalink
fix: serialization of \n, \r and \t to Line Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed Jun 29, 2020
1 parent d19ff96 commit 6d0312a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
1. [#112](https://github.com/influxdata/influxdb-client-python/pull/113): Support timestamp with different timezone in _convert_timestamp

### Bug Fixes
1. [#115](https://github.com/influxdata/influxdb-client-python/pull/115): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol
1. [#117](https://github.com/influxdata/influxdb-client-python/pull/117): Fixed appending default tags for single Point

## 1.8.0 [2020-06-19]
Expand Down
2 changes: 1 addition & 1 deletion influxdb_client/client/write/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

EPOCH = UTC.localize(datetime.utcfromtimestamp(0))
DEFAULT_WRITE_PRECISION = WritePrecision.NS
_ESCAPE_KEY = str.maketrans({'\\': '\\\\', ',': r'\,', ' ': r'\ ', '=': r'\=', '\n': ''})
_ESCAPE_KEY = str.maketrans({'\\': '\\\\', ',': r'\,', ' ': r'\ ', '=': r'\=', '\n': '\\n', '\t': '\\t', '\r': '\\r'})
_ESCAPE_STRING = str.maketrans({'\"': r"\"", "\\": r"\\"})


Expand Down
10 changes: 10 additions & 0 deletions tests/test_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def test_TagEmptyValue(self):

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

def test_TagEscapingKeyAndValue(self):

point = Point.measurement("h\n2\ro\t_data") \
.tag("new\nline", "new\nline") \
.tag("carriage\rreturn", "carriage\nreturn") \
.tag("t\tab", "t\tab") \
.field("level", 2)

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())

def test_OverrideTagField(self):
point = Point.measurement("h2o") \
.tag("location", "europe") \
Expand Down

0 comments on commit 6d0312a

Please sign in to comment.