Skip to content

Commit

Permalink
Fix single quote parsing of TOML durations
Browse files Browse the repository at this point in the history
closes #2023
  • Loading branch information
sparrc committed Nov 14, 2016
1 parent 8ecfe13 commit 94de9dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 94de9dc

Please sign in to comment.