Trim null characters in Value data format (#2049)
* Trim null characters in Value data format Some producers (such as the paho embedded c mqtt client) add a null character "\x00" to the end of a message. The Value parser would fail on any message from such a producer. * Trim whitespace and null in all Value data formats * No unnecessary reassignments in Value data format parser * Update change log for Value data format fix
This commit is contained in:
committed by
Cameron Sparr
parent
94ce67cc67
commit
196509cc53
@@ -236,3 +236,18 @@ func TestParseValidValuesDefaultTags(t *testing.T) {
|
||||
}, metrics[0].Fields())
|
||||
assert.Equal(t, map[string]string{"test": "tag"}, metrics[0].Tags())
|
||||
}
|
||||
|
||||
func TestParseValuesWithNullCharacter(t *testing.T) {
|
||||
parser := ValueParser{
|
||||
MetricName: "value_test",
|
||||
DataType: "integer",
|
||||
}
|
||||
metrics, err := parser.Parse([]byte("55\x00"))
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, metrics, 1)
|
||||
assert.Equal(t, "value_test", metrics[0].Name())
|
||||
assert.Equal(t, map[string]interface{}{
|
||||
"value": int64(55),
|
||||
}, metrics[0].Fields())
|
||||
assert.Equal(t, map[string]string{}, metrics[0].Tags())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user