mirror of
https://github.com/nspcc-dev/neofs-node.git
synced 2026-03-01 04:29:10 +00:00
Check that all Cobra commands check length slice flags for emptiness if required #1233
Labels
No labels
I1
I2
I3
I4
S0
S1
S2
S3
S4
U0
U1
U2
U3
U4
blocked
bug
config
dependencies
discussion
documentation
enhancement
enhancement
epic
feature
go
good first issue
help wanted
neofs-adm
neofs-cli
neofs-cli
neofs-cli
neofs-ir
neofs-lens
neofs-storage
neofs-storage
performance
question
security
task
test
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nspcc-dev/neofs-node#1233
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cthulhu-rider on GitHub (Jun 28, 2024).
https://pkg.go.dev/github.com/spf13/cobra is a std engine for NeoFS command line tools. Some commands accept declare flag(s) of slice/array type. They are passed as
--flag XXX --flag XXX .... Then Cobra parses them into Go[]Twhere exactTvaries, e.g.StringSlicethere is one feature (???) of parsing such flags: a missing optional flag is treated the same as an explicitly specified with empty values:
note that if
--flagis marked required, then 1st command willError: required flag(s) "oid" not setwhile 2nd is still parsed as an empty slicethis not very obvious behavior can make the execution of some commands quite unexpected. For example, when command does useful actions in
forloopExpected Behavior
when command accepts slice flag and parses each element which must not be an empty string (like container/object/user IDs), passing
--flag ""leads to zero-len failureCurrent Behavior
if command checks flag len explicitly - fail, otherwise empty element just lost, and command may become even no-op
Possible Solution
always check length of required slice/array flags
Steps to Reproduce (for bugs)
Context
this may also appear when working with env vars:
if
OIDwill be empty for some reason, this wont be detectedRegression
no
Your Environment
neofs-cli@v0.42.1@cthulhu-rider commented on GitHub (Jun 28, 2024):
the reason is pretty understandable: such flags are CSV. For example,
--flag ","is["", ""]