Skip to content

Commit

Permalink
Merge pull request #5 from alsuren/escape-values
Browse files Browse the repository at this point in the history
escape tag values
  • Loading branch information
ijagberg authored Sep 8, 2024
2 parents 8e8f7a7 + bc03753 commit ba8cb9f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ struct TagValue(String);

impl TagValue {
fn new(s: String) -> Self {
let s = s.replace(' ', "\\ ");
let s = s
.replace(',', "\\,")
.replace('=', "\\=")
.replace(' ', "\\ ");
Self(s)
}
}
Expand Down Expand Up @@ -355,4 +358,19 @@ mod tests {
}
);
}

#[test]
fn measurement_escaping() {
let m = Measurement::builder("example_measurement")
.tag("agent", "KHTML, like Gecko")
.field("count", 1.0)
.timestamp_ms(1602321877560)
.build()
.unwrap();

assert_eq!(
m.to_line_protocol(),
r#"example_measurement,agent=KHTML\,\ like\ Gecko count=1 1602321877560"#,
);
}
}

0 comments on commit ba8cb9f

Please sign in to comment.