-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go-yaml accepts invalid durations #200
Comments
This has changed as suggested in v3, so time.Duration won't accept decoding from ints. Will close this once v3 is released. |
niemeyer
added a commit
that referenced
this issue
Apr 3, 2019
It used to work in v2, but that's very error prone as it's easy to say, for example, 10 meaning 10 seconds, but it's really 10 nanoseconds. Closes #200.
@niemeyer I think may be accept "0" as validate time.Duration and reject any other int is more convenience to use~ |
Unmarshaling of |
colega
added a commit
to colega/go-yaml-yaml
that referenced
this issue
Jul 20, 2022
While in go-yaml#200 it was correctly stated that durations without units are misleading, there's an exception to that: zero duration. This is a special case in time.Duration.ParseDuration(): https://github.com/golang/go/blob/176b63e7113b82c140a4ecb2620024526c2c42e3/src/time/format.go#L1536-L1539 And supporting this improves backwards compatibility with YAMLs written for v2, as its very common to write just a zero for zero duration (especially because this works for other config-parsing sources like flags). Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
colega
added a commit
to colega/go-yaml-yaml
that referenced
this issue
Jul 20, 2022
While in go-yaml#200 it was correctly stated that durations without units are misleading, there's an exception to that: zero duration. This is a special case in time.Duration.ParseDuration(): https://github.com/golang/go/blob/176b63e7113b82c140a4ecb2620024526c2c42e3/src/time/format.go#L1536-L1539 And supporting this improves backwards compatibility with YAMLs written for v2, as its very common to write just a zero for zero duration (especially because this works for other config-parsing sources like flags). Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you call ParseDuration with an invalid duration (e.g.
15
) it errors: https://play.golang.org/p/WAq-o3NT3DHowever, if you use go-yaml and try to marshal an invalid duration such as
15
into atime.Duration
, it accepts it and treats it as a number of nanoseconds.test.yaml
test.go
output
The text was updated successfully, but these errors were encountered: