Skip to content
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

fix(encode_logfmt): correctly handle values with equal signs #294

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Changes from 3 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
22 changes: 21 additions & 1 deletion src/core/encode_key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ fn encode_field(output: &mut String, key: &str, value: &str, key_value_delimiter
}

fn encode_string(output: &mut String, str: &str) {
let needs_quoting = str.chars().any(|c| c.is_whitespace() || c == '"');
let needs_quoting = str
.chars()
.any(|c| c.is_whitespace() || c == '"' || c == '=');

if needs_quoting {
output.write_char('"').unwrap();
Expand Down Expand Up @@ -571,6 +573,24 @@ mod tests {
);
}

#[test]
fn string_with_equal_sign() {
assert_eq!(
&to_string::<Value>(
&btreemap! {
"lvl" => "info",
"msg" => "="
},
&[],
"=",
" ",
true
)
.unwrap(),
r#"lvl=info msg="=""#
);
}

#[test]
fn flatten_boolean() {
assert_eq!(
Expand Down