mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-13 13:02:28 +00:00
LibC: Treat argument "-" the same as arguments that don't start with "-"
This causes `echo -` to output "-" instead of crashing
This commit is contained in:
parent
ad25a415ae
commit
c2cc01c920
Notes:
sideshowbarker
2024-07-17 03:57:44 +09:00
Author: https://github.com/BrendanKelly84213 🔰
Commit: c2cc01c920
Pull-request: https://github.com/SerenityOS/serenity/pull/16116
Issue: https://github.com/SerenityOS/serenity/issues/16107
Reviewed-by: https://github.com/AtkinsSJ ✅
1 changed files with 4 additions and 5 deletions
|
@ -321,15 +321,14 @@ bool OptionParser::find_next_option()
|
|||
for (m_arg_index = optind; m_arg_index < m_argc && m_argv[m_arg_index]; m_arg_index++) {
|
||||
StringView arg = current_arg();
|
||||
// Anything that doesn't start with a "-" is not an option.
|
||||
if (!arg.starts_with('-')) {
|
||||
// As a special case, a single "-" is not an option either.
|
||||
// (It's typically used by programs to refer to stdin).
|
||||
if (!arg.starts_with('-') || arg == "-") {
|
||||
if (m_stop_on_first_non_option)
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
// As a special case, a single "-" is not an option either.
|
||||
// (It's typically used by programs to refer to stdin).
|
||||
if (arg == "-")
|
||||
continue;
|
||||
|
||||
// As another special case, a "--" is not an option either, and we stop
|
||||
// looking for further options if we encounter it.
|
||||
if (arg == "--")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue