Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
chore(deps): update commons-lang3 and fix parsing boolean in LineProt…
Browse files Browse the repository at this point in the history
…ocolParser (#87)
  • Loading branch information
bednar authored Jul 19, 2022
1 parent 333e990 commit ef4887c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#### Build:
- influxdb-java to 2.23
- commons-io to 2.11
- commons-lang3 to 3.12.0
- gson to 2.9.0

#### Test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.influxdata.nifi.serialization;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -38,6 +39,11 @@ public final class InfluxLineProtocolParser {

private static final Logger LOG = LoggerFactory.getLogger(InfluxLineProtocolParser.class);

/**
* <a href="https://docs.influxdata.com/influxdb/latest/reference/syntax/line-protocol/#boolean">Boolean accepted values</a>
*/
private static final List<String> BOOLEAN_ACCEPTED = Arrays.asList("t", "true", "f", "false");

// Internal
private String lineProtocol;
private String[] tokens;
Expand Down Expand Up @@ -394,9 +400,13 @@ Object transformValue(@NonNull final String value) {
return Long.parseLong(value.substring(0, value.length() - 1));
}

Boolean bool = BooleanUtils.toBooleanObject(value);
if (bool != null) {
return bool;
// We don't want parse the '0', '1' ... as a boolean. Accepted values:
// https://docs.influxdata.com/influxdb/latest/reference/syntax/line-protocol/#boolean
if (BOOLEAN_ACCEPTED.contains(value.toLowerCase())) {
Boolean bool = BooleanUtils.toBooleanObject(value);
if (bool != null) {
return bool;
}
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.slf4j.LoggerFactory;

/**
* The tests comes from https://github.com/influxdata/influxdb/blob/1.6/models/points_test.go.
* The tests comes from <a href="https://github.com/influxdata/influxdb/blob/1.6/models/points_test.go">points_test.go</a>.
*/
public class TestInfluxLineProtocolParser {

Expand Down Expand Up @@ -1035,6 +1035,17 @@ public void tagsAreNotNull() throws NotParsableInlineProtocolData
Assert.assertTrue(parser.getTags().isEmpty());
}

@Test
public void onlyValidBooleans() {

ExpectedResult.success()
.measurement("b")
.field("float1", 1F)
.field("float2", 0F)
.field("float3", 1.0F)
.validate("b float1=1,float2=0,float3=1.0");
}

private static final class ExpectedResult {

private static final Logger LOG = LoggerFactory.getLogger(ExpectedResult.class);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
<version>3.12.0</version>
</dependency>

</dependencies>
Expand Down

0 comments on commit ef4887c

Please sign in to comment.