Skip to content

Commit 65c5281

Browse files
committed
Properly escape spaces in tags. Closes influxdata#38
1 parent 4b48f83 commit 65c5281

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/main/java/org/influxdb/dto/Point.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ public String lineProtocol() {
202202
sb.append(this.measurement);
203203
for (Entry<String, String> tag : this.tags.entrySet()) {
204204
sb.append(",");
205-
sb.append(tag.getKey()).append("=").append(tag.getValue());
205+
String value = tag.getValue().replace(" ", "\\ ");
206+
sb.append(tag.getKey()).append("=").append(value);
206207
}
207208
sb.append(" ");
208209
int fieldCount = this.fields.size();
@@ -222,5 +223,4 @@ public String lineProtocol() {
222223
}
223224
return sb.toString();
224225
}
225-
226226
}

src/test/java/org/influxdb/InfluxDBTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void setUp() throws InterruptedException, IOException {
9393
// String logs = CharStreams.toString(new InputStreamReader(containerLogsStream,
9494
// Charsets.UTF_8));
9595
System.out.println("##################################################################################");
96-
// System.out.println("CContainer Logs: \n" + logs);
96+
// System.out.println("Container Logs: \n" + logs);
9797
System.out.println("# Connected to InfluxDB Version: " + this.influxDB.version() + " #");
9898
System.out.println("##################################################################################");
9999
}
@@ -181,4 +181,22 @@ public void testWrite() {
181181
this.influxDB.query(query);
182182
this.influxDB.deleteDatabase(dbName);
183183
}
184+
185+
@Test(enabled = true)
186+
public void testTicket38() {
187+
String dbName = "ticket38_" + System.currentTimeMillis();
188+
this.influxDB.setLogLevel(LogLevel.FULL);
189+
this.influxDB.createDatabase(dbName);
190+
Point point1 = Point
191+
.measurement("metric")
192+
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
193+
.field("value", 5)
194+
.tag("host", "host A")
195+
.tag("host", "host-B")
196+
.tag("host", "host-\"C")
197+
.tag("region", "region")
198+
.build();
199+
this.influxDB.write(dbName, "default", point1);
200+
this.influxDB.deleteDatabase(dbName);
201+
}
184202
}

0 commit comments

Comments
 (0)