ip: stop GetIP erroring when the IP flag has a nil default#478
Open
c-tonneslan wants to merge 1 commit into
Open
ip: stop GetIP erroring when the IP flag has a nil default#478c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
IP("ip", nil, "...") followed by GetIP("ip") returned
"invalid string being converted to IP address: <nil>" instead of
(nil, nil). The flag's stored value is a nil net.IP, which
net.IP.String renders as "<nil>", so ipConv saw that literal string
and net.ParseIP rejected it.
Treat "" and "<nil>" as "no IP" in ipConv, matching Set's empty-input
behaviour, so a nil default round-trips cleanly through GetIP.
Fixes spf13#351
Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
2 tasks
Collaborator
|
@c-tonneslan Thanks for the contribution! Please sign the CLA, and hit recheck on the bot comment above if it doesn't automatically detect that you did so. |
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.
Reporter's case from #351:
The flag's underlying value is a nil
net.IP. WhenGetIPruns,getFlagTyperound-trips throughValue.String(), andnet.IP(nil).String()returns the literal"<nil>".ipConvthen hands that tonet.ParseIP, which rejects it.Set("")already short-circuits without storing anything, so an empty value is the existing "no IP" sentinel. Mirror that on the read side: whenipConvsees""or"<nil>", return(net.IP(nil), nil)instead of erroring.The fix is one branch in
ipConv.IPVar(&p, "ip", nil, ...)works the same way.Regression test covers both
IPandIPVarwith a nil default. Fails on master, passes here.go test ./...is clean.Fixes #351.