From 94de9dca1fc6efb3a4bf3ec6869c356278c6755a 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 | 9 +++++++++ internal/internal.go | 3 ++- internal/internal_test.go | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2df116d1..c1b0769d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ ### Bugfixes ## v1.1 [unreleased] +- [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin. + +## 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)