parse-options: report uncorrupted multi-byte options
Because our command-line parser considers only one byte at the time for short-options, we incorrectly report only the first byte when multi-byte input was provided. This makes user-errors slightly awkward to diagnose for instance under UTF-8 locale and non-English keyboard layouts. Report the whole argument-string when a non-ASCII short-option is detected. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Improved-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Erik Faye-Lund committed
Feb 12, 2013 at 00:13 UTC
b141a47801d6fb2d68ec48adfe7597ec3ce49c0d
1 file changed
+4
-1
parse-options.c
+4
-1
@@ -470,8 +470,11 @@ int parse_options(int argc, const char **argv, const char *prefix,
470
default: /* PARSE_OPT_UNKNOWN */
471
if (ctx.argv[0][1] == '-') {
472
error("unknown option `%s'", ctx.argv[0] + 2);
473
- } else {
473
+ } else if (isascii(*ctx.opt)) {
474
error("unknown switch `%c'", *ctx.opt);
475
+ } else {
476
+ error("unknown non-ascii option in string: `%s'",
477
+ ctx.argv[0]);
478
}
479
usage_with_options(usagestr, options);
480
}