Skip to content
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

Missing arg can cause a panic #1864

Merged
merged 3 commits into from
Feb 12, 2024
Merged

Conversation

joshfrench
Copy link
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

  • In the special case where an arg has max: 1, args.Parse would panic when arg was omitted.
  • Also ensure omitted args retain their Value, if provided.
--- FAIL: TestSingleOptionalArg (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
        panic: runtime error: index out of range [0] with length 0

goroutine 15 [running]:
testing.tRunner.func1.2({0x163bc20, 0xc00001c660})
        /usr/local/Cellar/go/1.21.4/libexec/src/testing/testing.go:1545 +0x366
testing.tRunner.func1()
        /usr/local/Cellar/go/1.21.4/libexec/src/testing/testing.go:1548 +0x630
panic({0x163bc20?, 0xc00001c660?})
        /usr/local/Cellar/go/1.21.4/libexec/src/runtime/panic.go:920 +0x270
github.com/urfave/cli/v3.(*ArgumentBase[...]).Parse(0x1729d40, {0xc0003381a0, 0x0?, 0x0})
        /Users/josh/src/cli/args.go:136 +0xc88

Testing

Tests added for an omitted arg with max: 1, with and without a default Value.

Release Notes

Optional arguments with arity 1 no longer panic when omitted.

args_test.go Show resolved Hide resolved
Copy link
Contributor

@dearchap dearchap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joshfrench

@dearchap dearchap merged commit e1d1334 into urfave:main Feb 12, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants