From 0ecbf9e34967af83d2a904686398a0e86afa7d7f Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Wed, 9 Nov 2016 16:35:58 +0000 Subject: [PATCH] Fix single quote parsing of TOML durations closes #2023 --- CHANGELOG.md | 8 +++++++- internal/internal.go | 3 ++- internal/internal_test.go | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 280a51876..dcd3b43d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,13 @@ - [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin. -## v1.1 [unreleased] +## v1.1.1 [unreleased] + +### Bugfixes + +- [#2023](https://github.com/influxdata/telegraf/issues/2023): Fix issue parsing toml durations with single quotes. + +## v1.1.0 [2016-11-07] ### Release Notes diff --git a/internal/internal.go b/internal/internal.go index 28b37c09f..aae7aa773 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -35,8 +35,9 @@ type Duration struct { // UnmarshalTOML parses the duration from the TOML config file func (d *Duration) UnmarshalTOML(b []byte) error { var err error + b = bytes.Trim(b, `'`) - // see if we can straight convert it + // see if we can directly convert it d.Duration, err = time.ParseDuration(string(b)) if err == nil { return nil diff --git a/internal/internal_test.go b/internal/internal_test.go index 0d9821857..aafc1929a 100644 --- a/internal/internal_test.go +++ b/internal/internal_test.go @@ -142,6 +142,10 @@ func TestDuration(t *testing.T) { d.UnmarshalTOML([]byte(`1s`)) assert.Equal(t, time.Second, d.Duration) + d = Duration{} + d.UnmarshalTOML([]byte(`'1s'`)) + assert.Equal(t, time.Second, d.Duration) + d = Duration{} d.UnmarshalTOML([]byte(`10`)) assert.Equal(t, 10*time.Second, d.Duration)