getopts icon indicating copy to clipboard operation
getopts copied to clipboard

getopts only works with UTF-8 strings, cannot process non-UTF-8 filenames

Open samuela opened this issue 4 years ago • 3 comments

See https://github.com/samuela/rustybox/pull/32#discussion_r445116643. This has been a factor in https://github.com/uutils/coreutils migrating from getopts to clap.

samuela avatar Jun 24 '20 21:06 samuela

Same issue in a similar project that was just brought to my attention: https://github.com/google/argh/issues/33

FWIW @samuela, that looks like it's gaining a bit of traction.

joshuarli avatar Jul 03 '20 17:07 joshuarli

If it's possible to fix this up without breakage then we'd happily accept a patch to support non-UTF8 args. Otherwise I think we'll probably have to accept the UTF8 requirement as a limitation of getopts.

KodrAus avatar Dec 21 '20 09:12 KodrAus

It might be possible but the field Matches::free has type Vec<String> so any additional path argument can't be collected into it without being valid UTF8. It would be necessary to add an additional field with type Vec<OsString> to avoid interface breakage, this is possible as there are private fields, and some opt-in method to populate the field instead of free.

I can provide a patch but want to know if this direction might be potentially accepted before working on it.

HeroicKatora avatar Mar 02 '21 18:03 HeroicKatora