From f93c27d86bfc0c40c84c186ac2c00c553bd69470 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Mon, 26 Aug 2024 09:19:22 -0400 Subject: [PATCH] Set encoding index correctly --- ruby.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ruby.c b/ruby.c index 410deea997..39ee4c20aa 100644 --- a/ruby.c +++ b/ruby.c @@ -2121,13 +2121,25 @@ prism_script_shebang_callback(pm_options_t *options, const uint8_t *source, size memcpy(switches, source, length); switches[length] = '\0'; + int no_src_enc = !opt->src.enc.name; + int no_ext_enc = !opt->ext.enc.name; + int no_int_enc = !opt->intern.enc.name; + moreswitches(switches, opt, 0); free(switches); pm_options_command_line_set(options, prism_script_command_line(opt)); - if (opt->ext.enc.name != 0) { + + if (no_src_enc && opt->src.enc.name) { + opt->src.enc.index = opt_enc_index(opt->src.enc.name); pm_options_encoding_set(options, StringValueCStr(opt->ext.enc.name)); } + if (no_ext_enc && opt->ext.enc.name) { + opt->ext.enc.index = opt_enc_index(opt->ext.enc.name); + } + if (no_int_enc && opt->intern.enc.name) { + opt->intern.enc.index = opt_enc_index(opt->intern.enc.name); + } } /**