Skip to content

Commit

Permalink
parse-options: report uncorrupted multi-byte options
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Erik Faye-Lund authored and Junio C Hamano committed Feb 11, 2013
1 parent 901fd18 commit b141a47
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,11 @@ int parse_options(int argc, const char **argv, const char *prefix,
default: /* PARSE_OPT_UNKNOWN */
if (ctx.argv[0][1] == '-') {
error("unknown option `%s'", ctx.argv[0] + 2);
} else {
} else if (isascii(*ctx.opt)) {
error("unknown switch `%c'", *ctx.opt);
} else {
error("unknown non-ascii option in string: `%s'",
ctx.argv[0]);
}
usage_with_options(usagestr, options);
}
Expand Down

0 comments on commit b141a47

Please sign in to comment.