From 37f7818bbb893348001b4f8ee2adb0bc78e33aac Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 10 Aug 2022 16:55:56 +0200 Subject: [PATCH] printf: Ignore any options This was misguidedly "fixed" in 9e08609f8543b81e35f5043dc0280cc9c30f0f70, which made printf error out with any "-"-prefixed words as the first argument. Note: This means currently `printf --help` doesn't print the help. This also matches `echo`, and we currently don't have anything to make a literal `--help` execute a builtin help except for keywords. Oh well. Fixes #9132 --- src/builtins/printf.cpp | 13 ++----------- tests/checks/printf.fish | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/builtins/printf.cpp b/src/builtins/printf.cpp index d1a7f17ae..ec4c1c6fd 100644 --- a/src/builtins/printf.cpp +++ b/src/builtins/printf.cpp @@ -649,19 +649,10 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, con maybe_t builtin_printf(parser_t &parser, io_streams_t &streams, const wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - help_only_cmd_opts_t opts; - int optind; - int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); - if (retval != STATUS_CMD_OK) return retval; + argv++; + argc--; - if (opts.print_help) { - builtin_print_help(parser, streams, cmd); - return STATUS_CMD_OK; - } - - argc -= optind; - argv += optind; if (argc < 1) { return STATUS_INVALID_ARGS; } diff --git a/tests/checks/printf.fish b/tests/checks/printf.fish index 6b7d52795..cecbbaa12 100644 --- a/tests/checks/printf.fish +++ b/tests/checks/printf.fish @@ -119,3 +119,18 @@ printf '%d\n' 0g # CHECKERR: 0g: value not completely converted (can't convert 'g') echo $status # CHECK: 1 + +# Test that we ignore options +printf -a +printf --foo +# CHECK: -a--foo +echo + +set -l helpvar --help +printf $helpvar +echo +# CHECK: --help + +printf --help +echo +# CHECK: --help