Skip to content

Fix whitespace handling#53

Closed
satirebird wants to merge 2 commits intoinfluxdb-rs:masterfrom
satirebird:escape
Closed

Fix whitespace handling#53
satirebird wants to merge 2 commits intoinfluxdb-rs:masterfrom
satirebird:escape

Conversation

@satirebird
Copy link

@satirebird satirebird commented Mar 1, 2020

The whitespaces in tags and fields must be escaped with a backslash instead of surrounding it with double quotes.

I am not sure how to handle other special characters like \r, \n, or \t. This is not handled currently.

Closes #52

Sven Krauß added 2 commits March 1, 2020 16:30
The whitespaces in tags and fields must be escaped with a backslash instead of surrounding it with double quotes.
Copy link
Collaborator

@Empty2k12 Empty2k12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR 🚀

I left some comments about behavior specified in the InfluxDb Line Protocol docs. I think it makes sense to finally properly implement the escaping guidelines :)

SignedInteger(x) => write!(f, "{}", x),
UnsignedInteger(x) => write!(f, "{}", x),
Text(text) => write!(f, "\"{text}\"", text = text),
Text(text) => write!(f, "{text}", text = text.replace(" ", "\\ ")),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for removing these quotes? InfuxDb Docs says on quoting

Element Double quotes Single quotes
Timestamp Never Never
Measurements, tag keys, tag values, field keys Never* Never*
Field values Double quote string field values. Do not double quote floats, integers, or Booleans. Never

* InfluxDB line protocol allows users to double and single quote measurement names, tag keys, tag values, and field keys. It will, however, assume that the double or single quotes are part of the name, key, or value. This can complicate query syntax (see the example below).

I think it would be best if these guidelines were implemented. This will possibly break existing uses of this library as quoting field names is not recommended, but we did so far.

For escaping special characters, InfluxDb Docs suggest the following:

In string field values, you must escape:

  • double quotes
  • backslash character

In tag keys, tag values, and field keys, you must escape:

  • commas
  • equal signs
  • spaces

For example, , escapes a comma.

In measurements, you must escape:

  • commas
  • spaces

You do not need to escape other special characters.

That means we can safely ignore \r, \n, and \t.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to replace my existing python application and I wanted to keep the existing measurements. The python library doesn't add any kind of quotes. Whitespaces will be escaped with backslashes.
As the InfluxDB docs says, the quotes are part of the name. If I use the rust library I cannot append any data with the same tag key as before. The double quotes are always added. This was the reason for removing the quotes.
On the other hand, if someone updates the library to the new version the user must add the quotes in the application (if necessary). But this should be easy. I think adding the double quotes in the library code is an unnecessary restriction.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But...
there is a problem with the field values. The Type formatter is also used for the field values. If the field value is a string it must be quoted with double quotes. I think this is actually wrong and should be fixed prior.
Also the escaping should be completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spaces and double quotes

2 participants