-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LogfmtRenderer has a bug with escaped double quotes #511
Comments
Hmmm we've used the same approach as python-logfmter IIRC, so they've got the same bug if this is valid. I'm trying to wrap my head around this, but is there a more precise definition of of logfmt than https://brandur.org/logfmt? It feels like it accidentally did the right thing and escaped the backslash to preserve it? |
Sorry for the late answer, I didn't notice your reply before. The problem is that both the backslash and the quote needs to end up escaped, not only the backslash. That allows a parser to translate \" back to the original ". If, as it is implemented in structlog, you use \", then a parser will parse \ into , but then it will see just the double quote and interpret it as the end of the string. |
Chiming in, as requested. So, this looks like an issue with double escaping (which are always fun). The result is not completely specific to logfmt, it's the same thing you'd get if you were producing strings for bash or python or something. If I understand correctly:
I'll now take a stab at reviewing the PR. BTW, logfmt is a bit more specified in https://pkg.go.dev/github.com/kr/logfmt (there is an EBNF, ish). It is the reference implementation in go, anyways, and used in grafana and a lot of other tools. |
Okay, after thinking more on it, here are a set of test cases that I've validated against the grafana parser, that should cover this:
I don't think |
Thanks! quick summary before the work begins:
TODO :) |
In the code of LogFmtRenderer there is:
value = f"{value}".replace('"', '\\"')
However if you are trying to render an escaped double quote like
"I want to render this \"string\" with logfmtrenderer"
it ends up rendering it as
\"I want to render this \\"string\\" with logfmtrenderer\"
\\"
is wrong and won't be parsed correctly by a logfmtparser.The text was updated successfully, but these errors were encountered: