coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

basename: Fix handling of repeated flags/arguments

Open BenWiederhake opened this issue 1 year ago • 2 comments

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.

BenWiederhake avatar Feb 25 '24 18:02 BenWiederhake

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 on ubuntu-latest, x86_64-unknown-linux-musl, feat_os_unix_musl, use-cross)

BenWiederhake avatar Feb 25 '24 19:02 BenWiederhake

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Feb 25 '24 19:02 github-actions[bot]

Would you like to fix that upstream? I can do it if you want

sylvestre avatar Feb 26 '24 08:02 sylvestre

The documentation issue? That sounds fantastic, yes please! :)

BenWiederhake avatar Feb 26 '24 14:02 BenWiederhake

Good job, thanks!

cakebaker avatar Feb 27 '24 09:02 cakebaker