fix: parse errors and panics on edge-case values - #23
Merged
Conversation
- int fields no longer accept duration syntax (e.g. "10s" used to silently set the value to 1e10 nanoseconds); only time.Duration fields are parsed as durations - int/uint/float fields and pointers are parsed with their bit size so out-of-range values error out instead of being silently truncated - []int64 with duration-like values and []time.Duration with plain numbers no longer panic in reflect.Value.Set - *[]T pointer-to-slice fields now parse correctly - env values now overwrite non-nil pointer fields - parseScientific rejects negative exponents instead of silently returning a wrong number, and handles comma+exponent combos - Parse(&c) with c being a pointer no longer panics; nil or non-struct configs return an error, List returns an empty list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug fixes for edge-case values that previously produced silent wrong values, errors, or panics:
intfields no longer accept duration syntax (e.g.10sused to silently set the value to 1e10 nanoseconds); onlytime.Durationfields are parsed as durationsint/uint/floatfields and pointers are parsed with their bit size, so out-of-range values error out instead of being silently truncated[]int64with duration-like values and[]time.Durationwith plain numbers no longer panic inreflect.Value.Set*[]Tpointer-to-slice fields now parse correctly (previously failed with "field is not addressable")parseScientificrejects negative exponents (e.g.1e-3used to silently become1) and handles comma+exponent combos like1,000e3Parse(&c)wherecis already a pointer no longer panics; nil or non-struct configs return an error instead of panicking,Listreturns an empty listAll existing tests pass; 13 regression tests were added in
bugfix_test.go.