Fix single quote parsing of TOML durations

closes #2023
This commit is contained in:
Cameron Sparr 2016-11-09 16:35:58 +00:00
parent 5d3850c44e
commit 0ecbf9e349
3 changed files with 13 additions and 2 deletions

View File

@ -10,7 +10,13 @@
- [#1949](https://github.com/influxdata/telegraf/issues/1949): Fix windows `net` plugin. - [#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 ### Release Notes

View File

@ -35,8 +35,9 @@ type Duration struct {
// UnmarshalTOML parses the duration from the TOML config file // UnmarshalTOML parses the duration from the TOML config file
func (d *Duration) UnmarshalTOML(b []byte) error { func (d *Duration) UnmarshalTOML(b []byte) error {
var err 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)) d.Duration, err = time.ParseDuration(string(b))
if err == nil { if err == nil {
return nil return nil

View File

@ -142,6 +142,10 @@ func TestDuration(t *testing.T) {
d.UnmarshalTOML([]byte(`1s`)) d.UnmarshalTOML([]byte(`1s`))
assert.Equal(t, time.Second, d.Duration) assert.Equal(t, time.Second, d.Duration)
d = Duration{}
d.UnmarshalTOML([]byte(`'1s'`))
assert.Equal(t, time.Second, d.Duration)
d = Duration{} d = Duration{}
d.UnmarshalTOML([]byte(`10`)) d.UnmarshalTOML([]byte(`10`))
assert.Equal(t, 10*time.Second, d.Duration) assert.Equal(t, 10*time.Second, d.Duration)