diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-09-29 19:59:31 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-10-01 20:28:44 +0900 |
commit | 842b0008c132dd587f09766a228041afb7fed24f (patch) | |
tree | b7324862c67cfc7e28c0d4e4866b77f548019e6a /ruby.c | |
parent | 409dbc951b9875d27bd73748c88e15386473cffb (diff) |
Skip broken strings as the locale encoding
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4915
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -1680,7 +1680,11 @@ tty_enabled(void) static VALUE copy_str(VALUE str, rb_encoding *enc, bool intern) { - if (!intern) return rb_enc_associate(rb_str_dup(str), enc); + if (!intern) { + if (rb_enc_str_coderange_scan(str, enc) == ENC_CODERANGE_BROKEN) + return 0; + return rb_enc_associate(rb_str_dup(str), enc); + } return rb_enc_interned_str(RSTRING_PTR(str), RSTRING_LEN(str), enc); } @@ -1916,7 +1920,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) if (newpath == path) continue; path = newpath; #else - path = copy_str(path, lenc, !mark); + if (!(path = copy_str(path, lenc, !mark))) continue; #endif if (mark) rb_ivar_set(path, id_initial_load_path_mark, path); if (!modifiable) { @@ -1934,8 +1938,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) bool modified = false; for (long i = loaded_before_enc; i < RARRAY_LEN(loaded_features); ++i) { VALUE path = RARRAY_AREF(loaded_features, i); - if (rb_enc_get(path) == IF_UTF8_PATH(uenc, lenc)) continue; - path = copy_str(path, IF_UTF8_PATH(uenc, lenc), true); + if (!(path = copy_str(path, IF_UTF8_PATH(uenc, lenc), true))) continue; modified = true; RARRAY_ASET(loaded_features, i, path); } |