diff --git a/CHANGELOG.md b/CHANGELOG.md index 255be7dc..99134152 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ 1. [#283](https://github.com/influxdata/influxdb-client-python/pull/283): Set proxy server in config file 1. [#290](https://github.com/influxdata/influxdb-client-python/pull/290): `Threshold` domain models mapping 1. [#290](https://github.com/influxdata/influxdb-client-python/pull/290): `DashboardService` responses types +1. [#303](https://github.com/influxdata/influxdb-client-python/pull/303): Backslash escaping in serialization to Line protocol ## 1.19.0 [2021-07-09] diff --git a/influxdb_client/client/write/point.py b/influxdb_client/client/write/point.py index 98af23ee..04d3c9ca 100644 --- a/influxdb_client/client/write/point.py +++ b/influxdb_client/client/write/point.py @@ -18,7 +18,6 @@ DEFAULT_WRITE_PRECISION = WritePrecision.NS _ESCAPE_MEASUREMENT = str.maketrans({ - '\\': r'\\', # Note: this is wrong. Backslashes are not escaped like this in measurements. ',': r'\,', ' ': r'\ ', '\n': r'\n', @@ -27,7 +26,6 @@ }) _ESCAPE_KEY = str.maketrans({ - '\\': r'\\', # Note: this is wrong. Backslashes are not escaped like this in keys. ',': r'\,', '=': r'\=', ' ': r'\ ', diff --git a/tests/test_point.py b/tests/test_point.py index f37e3622..40446a9d 100644 --- a/tests/test_point.py +++ b/tests/test_point.py @@ -267,7 +267,7 @@ def test_lineprotocol_encode(self): point._tags = { "empty_tag": "", "none_tag": None, - "backslash_tag": "C:\\", + "backslash_tag": "C:\\\\", "integer_tag": 2, "string_tag": "hello" } @@ -379,6 +379,15 @@ def test_unsupported_field_type(self): self.assertEqual('Type: "" of field: "level" is not supported.', f'{exception}') + def test_backslash(self): + point = Point.from_dict({"measurement": "test", + "tags": {"tag1": "value1", "tag2": "value\2", "tag3": "value\\3", + "tag4": r"value\4", "tag5": r"value\\5"}, "time": 1624989000000000000, + "fields": {"value": 10}}, write_precision=WritePrecision.NS) + self.assertEqual( + "test,tag1=value1,tag2=value\2,tag3=value\\3,tag4=value\\4,tag5=value\\\\5 value=10i 1624989000000000000", + point.to_line_protocol()) + if __name__ == '__main__': unittest.main()