Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

fix: backslash escaping in serialization to Line protocol #899

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 0 additions & 4 deletions influxdb/line_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def _convert_timestamp(timestamp, precision=None):
def _escape_tag(tag):
tag = _get_unicode(tag, force=True)
return tag.replace(
"\\", "\\\\"
).replace(
" ", "\\ "
).replace(
",", "\\,"
Expand All @@ -82,15 +80,13 @@ def _escape_tag_value(value):
def quote_ident(value):
"""Indent the quotes."""
return "\"{}\"".format(value
.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\n", "\\n"))


def quote_literal(value):
"""Quote provided literal."""
return "'{}'".format(value
.replace("\\", "\\\\")
.replace("'", "\\'"))


Expand Down
6 changes: 3 additions & 3 deletions influxdb/tests/test_line_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_make_lines(self):

self.assertEqual(
line_protocol.make_lines(data),
'test,backslash_tag=C:\\\\,integer_tag=2,string_tag=hello '
'test,backslash_tag=C:\\,integer_tag=2,string_tag=hello '
'bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"\n'
)

Expand Down Expand Up @@ -160,14 +160,14 @@ def test_quote_ident(self):
"""Test quote indentation in TestLineProtocol object."""
self.assertEqual(
line_protocol.quote_ident(r"""\foo ' bar " Örf"""),
r'''"\\foo ' bar \" Örf"'''
r'''"\foo ' bar \" Örf"'''
)

def test_quote_literal(self):
"""Test quote literal in TestLineProtocol object."""
self.assertEqual(
line_protocol.quote_literal(r"""\foo ' bar " Örf"""),
r"""'\\foo \' bar " Örf'"""
r"""'\foo \' bar " Örf'"""
)

def test_float_with_long_decimal_fraction(self):
Expand Down