Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 0.4.0 [unreleased]

### Bug Fixes

1. [#49](https://github.com/InfluxCommunity/influxdb3-rust/pull/49): Extra validation on `Point#write_line_protocol()` to error out if fields contains any newline (`\n`) character.

## 0.3.0 [2026-08-27]

> ⚠️ This release requires Rust 1.91 or later.
Expand Down
31 changes: 31 additions & 0 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,37 @@ impl Point {
self.measurement
)));
}
// VALIDATION: '\n' characters are not supported
for (k, v) in self.tags() {
if k.contains('\n') || v.contains('\n') {
return Err(Error::Config(
format!(
"tag '{k}' contains a line break which is unsupported in line protocol; point '{}'",
self.measurement
)
));
}
}
for (k, v) in self.fields() {
if k.contains('\n') {
return Err(Error::Config(
format!(
"field '{k}' contains a line break which is unsupported in line protocol; point '{}'",
self.measurement
)
));
}
if let FieldValue::String(s) = v {
if s.contains('\n') {
return Err(Error::Config(
format!(
"field '{k}' contains a line break which is unsupported in line protocol; point '{}'",
self.measurement
)
));
}
}
}

// Measurement
write_escaped_measurement(buf, &self.measurement);
Expand Down
37 changes: 37 additions & 0 deletions tests/point_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,40 @@ fn last_write_wins() {
assert_eq!(lp.matches("v=").count(), 1);
assert!(lp.contains("v=2i"));
}

#[test]
#[should_panic = "contains a line break"]
fn tag_names_should_reject_newlines() {
Point::new("m")
.tag("t\nag", "value")
.field("v", 1)
.to_line_protocol(Precision::Nanosecond)
.unwrap();
}
#[test]
#[should_panic = "contains a line break"]
fn tag_values_should_reject_newlines() {
Point::new("m")
.tag("tag", "val\nue")
.field("v", 1)
.to_line_protocol(Precision::Nanosecond)
.unwrap();
}
#[test]
#[should_panic = "contains a line break"]
fn field_names_should_reject_newlines() {
Point::new("m")
.tag("tag", "value")
.field("fi\neld", 1)
.to_line_protocol(Precision::Nanosecond)
.unwrap();
}

#[test]
#[should_panic = "contains a line break"]
fn field_values_should_reject_newlines() {
Point::new("m")
.field("field", "val\nue")
.to_line_protocol(Precision::Nanosecond)
.unwrap();
}
Loading