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
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## unreleased
- enquote values containing `=` in `encode_logfmt` vrl function (https://github.com/vectordotdev/vector/issues/17855)
- breaking change to `parse_nginx_log()` to make it compatible to more unstandardized events (https://github.com/vectordotdev/vrl/pull/249)
- deprecated `to_timestamp` vrl function (https://github.com/vectordotdev/vrl/pull/285)

Expand Down
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