diff options
author | Nobuyoshi Nakada <[email protected]> | 2025-01-08 21:35:48 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2025-01-09 19:26:20 +0900 |
commit | dfe6b7c02efa3bc2f5426eb64107ac0ac45a66a4 (patch) | |
tree | ca5e3d3738e1bb644bb0b7480b9e2069e5ab47d1 /ruby.c | |
parent | d44a41d81423c2362af3dfc6d9f9f7c2f21038c1 (diff) |
[Bug #21018] Show invalid command line option more properly
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12538
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -1721,11 +1721,27 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) if (!s[1]) break; - default: + default: { + rb_encoding *enc = IF_UTF8_PATH(rb_utf8_encoding(), rb_locale_encoding()); + const char *e = s + strlen(s); + int r = rb_enc_precise_mbclen(s, e, enc); + unsigned int c = (unsigned char)*s; + if (r > 0) { + c = rb_enc_mbc_to_codepoint(s, e, enc); + if (ONIGENC_IS_CODE_GRAPH(enc, c) || + ((s = ruby_escaped_char(c)) != 0 && + (r = (int)strlen(s), /* 3 at most */ 1))) { + rb_enc_raise(enc, rb_eRuntimeError, + "invalid option -%.*s (-h will show valid options)", + r, s); + } + } rb_raise(rb_eRuntimeError, - "invalid option -%c (-h will show valid options)", - (int)(unsigned char)*s); + "invalid option -\\x%.2x (-h will show valid options)", + c); + goto switch_end; + } noenvopt: /* "EIdvwWrKU" only */ |