Skip to content

Conversation

@btertoolen
Copy link
Collaborator

Fixes #2579

POSIX specifies specific behavior when "--" is passed as an argument to getopts, but osh was not handling this case:
"The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character."
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

Furthermore getopts should return ? when it is processing "--" according to

@btertoolen btertoolen force-pushed the optarg-double-dash branch 3 times, most recently from 4cc5a94 to 8e26302 Compare November 15, 2025 17:19
@andychu andychu changed the base branch from master to soil-staging November 17, 2025 04:37
@andychu
Copy link
Contributor

andychu commented Nov 17, 2025

This looks great, thank you! Just a minor comment about the tests

@btertoolen
Copy link
Collaborator Author

@andychu I think the comment is missing

a
## END

#### getopts sets name to '?' when encountering '--' #2579
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can combine these 3 test cases

  • it processes the flag -a before --
  • it sets name to ?
  • it sets OPTIND

and then the last test case tests with args -c operand

So it could be 2 cases: without args after --, and with args

And in each case it checks 3 things

Copy link
Collaborator Author

@btertoolen btertoolen Nov 17, 2025

Choose a reason for hiding this comment

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

I had one test initially, but then I found out zsh failed it. So then I split it up to make it more clear what exactly zsh does differently. But then I found out that these tests don't run zsh, so it doesn't show up anyway. I tried adding zsh but it was failing a lot of test cases so I ended up leaving it out. Typing it out I guess there is indeed no more reason for these to be split up, so I'll merge it back into one

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I split it up into 2 tests, where the second test is more focussed on leaving the remaining args as operands

@andychu
Copy link
Contributor

andychu commented Nov 17, 2025

Oh sorry! I didn't "publish" my code review

@andychu andychu merged commit 19dbb2d into soil-staging Nov 22, 2025
19 checks passed
@andychu
Copy link
Contributor

andychu commented Nov 22, 2025

Thanks!

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.

makepasswd: osh doesn't handle longform args in optargs properly

3 participants