Skip to content

Commit

Permalink
fix: backslash escaping in serialization to Line protocol (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Aug 16, 2021
1 parent 569223c commit ad58f9e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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]

Expand Down
2 changes: 0 additions & 2 deletions influxdb_client/client/write/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -27,7 +26,6 @@
})

_ESCAPE_KEY = str.maketrans({
'\\': r'\\', # Note: this is wrong. Backslashes are not escaped like this in keys.
',': r'\,',
'=': r'\=',
' ': r'\ ',
Expand Down
11 changes: 10 additions & 1 deletion tests/test_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -379,6 +379,15 @@ def test_unsupported_field_type(self):

self.assertEqual('Type: "<class \'pytz.UTC\'>" 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()

0 comments on commit ad58f9e

Please sign in to comment.