Fix the encoding of loaded feature names [Bug #18191]
The feature names loaded from the default load paths should also be in the file system encoding.
This commit is contained in:
parent
8e9d696ed0
commit
60d0421ca8
Notes:
git
2021-10-01 20:29:14 +09:00
12
ruby.c
12
ruby.c
@ -1693,6 +1693,8 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
|
|||||||
char fbuf[MAXPATHLEN];
|
char fbuf[MAXPATHLEN];
|
||||||
int i = (int)proc_options(argc, argv, opt, 0);
|
int i = (int)proc_options(argc, argv, opt, 0);
|
||||||
unsigned int dump = opt->dump & dump_exit_bits;
|
unsigned int dump = opt->dump & dump_exit_bits;
|
||||||
|
rb_vm_t *vm = GET_VM();
|
||||||
|
const long loaded_before_enc = RARRAY_LEN(vm->loaded_features);
|
||||||
|
|
||||||
if (opt->dump & (DUMP_BIT(usage)|DUMP_BIT(help))) {
|
if (opt->dump & (DUMP_BIT(usage)|DUMP_BIT(help))) {
|
||||||
int tty = isatty(1);
|
int tty = isatty(1);
|
||||||
@ -1894,7 +1896,6 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
|
|||||||
rb_obj_freeze(opt->script_name);
|
rb_obj_freeze(opt->script_name);
|
||||||
if (IF_UTF8_PATH(uenc != lenc, 1)) {
|
if (IF_UTF8_PATH(uenc != lenc, 1)) {
|
||||||
long i;
|
long i;
|
||||||
rb_vm_t *vm = GET_VM();
|
|
||||||
VALUE load_path = vm->load_path;
|
VALUE load_path = vm->load_path;
|
||||||
const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK;
|
const ID id_initial_load_path_mark = INITIAL_LOAD_PATH_MARK;
|
||||||
int modifiable = FALSE;
|
int modifiable = FALSE;
|
||||||
@ -1921,6 +1922,15 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
|
|||||||
rb_ary_replace(vm->load_path_snapshot, load_path);
|
rb_ary_replace(vm->load_path_snapshot, load_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
VALUE loaded_features = vm->loaded_features;
|
||||||
|
for (long i = loaded_before_enc; i < RARRAY_LEN(loaded_features); ++i) {
|
||||||
|
VALUE path = RARRAY_AREF(loaded_features, i);
|
||||||
|
path = rb_enc_associate(rb_str_dup(path), IF_UTF8_PATH(uenc, lenc));
|
||||||
|
RARRAY_ASET(loaded_features, i, path);
|
||||||
|
}
|
||||||
|
rb_get_expanded_load_path();
|
||||||
|
}
|
||||||
|
|
||||||
if (opt->features.mask & COMPILATION_FEATURES) {
|
if (opt->features.mask & COMPILATION_FEATURES) {
|
||||||
VALUE option = rb_hash_new();
|
VALUE option = rb_hash_new();
|
||||||
|
@ -531,6 +531,28 @@ class TestRequire < Test::Unit::TestCase
|
|||||||
$".replace(features)
|
$".replace(features)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_default_loaded_features_encoding
|
||||||
|
Dir.mktmpdir {|tmp|
|
||||||
|
Dir.mkdir("#{tmp}/1")
|
||||||
|
Dir.mkdir("#{tmp}/2")
|
||||||
|
File.write("#{tmp}/1/bug18191-1.rb", "")
|
||||||
|
File.write("#{tmp}/2/bug18191-2.rb", "")
|
||||||
|
assert_separately(%W[-Eutf-8 -I#{tmp}/1 -], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
|
tmp = #{tmp.dump}"/2"
|
||||||
|
begin;
|
||||||
|
$:.unshift(tmp)
|
||||||
|
require "bug18191-1"
|
||||||
|
require "bug18191-2"
|
||||||
|
encs = [Encoding::US_ASCII, Encoding.find("filesystem")]
|
||||||
|
message = -> {
|
||||||
|
require "pp"
|
||||||
|
{filesystem: encs[1], **$".group_by(&:encoding)}.pretty_inspect
|
||||||
|
}
|
||||||
|
assert($".all? {|n| encs.include?(n.encoding)}, message)
|
||||||
|
end;
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_require_changed_current_dir
|
def test_require_changed_current_dir
|
||||||
bug7158 = '[ruby-core:47970]'
|
bug7158 = '[ruby-core:47970]'
|
||||||
Dir.mktmpdir {|tmp|
|
Dir.mktmpdir {|tmp|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user