Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

args_from_usage() has issues with non-ASCII identifiers #664

Closed
tormol opened this issue Sep 15, 2016 · 4 comments
Closed

args_from_usage() has issues with non-ASCII identifiers #664

tormol opened this issue Sep 15, 2016 · 4 comments
Labels
C-enhancement Category: Raise on the bar on expectations

Comments

@tormol
Copy link
Contributor

tormol commented Sep 15, 2016

Non-ASCII help on its own is OK:
clap::App::new("").args_from_usage("<h> 'with ŭnicode'"); works

If the last character is non-ascii there are slice errors:
clap::App::new("").args_from_usage("<hæ> 'comment doesn't matter'");

If both name and help has non-ascii the program hangs:
clap::App::new("").args_from_usage("<øh> 'with ŭnicode'");

If only the name is non-ascii the argument is not detected:
clap::App::new("").args_from_usage("<øh> 'ASCII or empty'").get_matches().value_of("øh").unwrap()

The first three act the same with options, but this is different:
clap::App::new("").args_from_usage("--øh 'ASCII'").get_matches(); gives this error:

error: Found argument '--øh' which wasn't expected, or isn't valid in this context
    Did you mean --ø?

USAGE:
    clapbug --ø <ASCII'>

For more information try --help

Arg::with_name() has none of these issues.

@kbknapp
Copy link
Member

kbknapp commented Sep 16, 2016

Originally the from_usage parser was designed around ASCII only support (where as full Arg methods support any valid UTF-8). I agree this is something I need to add, and a feature I'd like to have. I'll add it to the issue tracker, but there a few other things I need to implement before this.

Thanks for taking the time to request and file this! 👍

@kbknapp kbknapp added C-enhancement Category: Raise on the bar on expectations C: args labels Sep 16, 2016
@tormol
Copy link
Contributor Author

tormol commented Sep 17, 2016

This is a niche issue, and easy to work around.
Asserting that the identifiers are ascii to fail in a consistent way should be enough.

@nabijaczleweli
Copy link
Contributor

Why'd you ever fail when it can actually work though?

tormol added a commit to tormol/clap-rs that referenced this issue Sep 27, 2016
tormol added a commit to tormol/clap-rs that referenced this issue Sep 30, 2016
This should also speeds up the parser (except maybe for short options).
Multi-codepoint characters still can't be used as short options, but people shouldn't non-ASCII options nyway.

Closes clap-rs#664
@tormol
Copy link
Contributor Author

tormol commented Sep 30, 2016

If it was difficult to make it work. I did it anyway.

homu added a commit that referenced this issue Oct 4, 2016
Handle non-ascii names / options in from_usage().

Closes #664 and should make it faster too.

Why aren't the stop_at functions written like `c != a && c != b`?
@homu homu closed this as completed in #670 Oct 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

3 participants