DevoInc / python-sdk

SDK for Python (devo-sdk). Send events to Devo and make queries.

Home Page:https://www.devo.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lookup API is unable to send records with a double quote character in their content

pavel-kalmykov opened this issue · comments

Right now, the Lookup.clean_field method wraps the field's content in double quotes, unless it is a number:

@staticmethod
def clean_field(field=None):
"""
Strip and quotechar the fields
:param str field: field for clean
:return str: cleaned field
"""
if not isinstance(field, (str, bytes)):
return field
field = field.strip()
if Lookup.is_number(field):
return field
return '"%s"' % field

However, it does not check the existence of double quotes present in the field's value itself. This leads to a problem in which a code like this:

lookup.send_headers(headers=['KEY', 'VALUE'], key='KEY', event='START', action="INC")
lookup.send_data_line(key="11", fields=["11", 'double quote: "'])
lookup.send_headers(headers=['KEY', 'VALUE'], key='KEY', event='END', action="INC")

Makes the update process fail silently, without any notice from the client's perspective.

I think we need to ensure that double quotes are escaped by replacing them like this:

field.replace('"', '""')

Or at least inform in the documentation that double quotes need to be escaped with two double quotes.

We will follow both approaches: document this and allow the user to automatically escape the double quotes (through a parameters flag or something like that).