coreutils
coreutils copied to clipboard
basename: Fix handling of repeated flags/arguments
This fixes several GNU behavior bugs around repeated arguments. In my eyes, the parsing code is now simpler, too.
Note in particular that args_override_self would NOT work here, since it would in all cases cause options::NAME to override itself, or interfere with trailing_var_arg.
This fixes #5998 for the special case of basename.
Notes on the GNU documentation bug
The GNU basename help suggests that -z immediately implies "multi-name mode", because it cannot appear in the first pattern:
$ basename --help
Usage: basename NAME [SUFFIX]
or: basename OPTION... NAME...
However, that is evidently wrong:
$ basename -z tool l | hd
00000000 74 6f 6f 00 |too.|
00000004
If -z would imply multi-name mode, this should have interpreted l as a second file name, but it was obviously parsed as the suffix-to-be-removed.
Hence a bug in the --help string. And that's why I also changed our basename.md.
CI errors are only flakes:
test_uniq::gnu_tests(would be fixed by #6017)test_cp::test_cp_arg_interactive_update(known issue #4725, but this time onubuntu-latest, x86_64-unknown-linux-musl, feat_os_unix_musl, use-cross)
GNU testsuite comparison:
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
Would you like to fix that upstream? I can do it if you want
The documentation issue? That sounds fantastic, yes please! :)
Good job, thanks!