summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c6
-rw-r--r--test/ruby/test_io_m17n.rb11
2 files changed, 14 insertions, 3 deletions
diff --git a/io.c b/io.c
index ddd9f1a9ff3..62a948093d9 100644
--- a/io.c
+++ b/io.c
@@ -5194,9 +5194,9 @@ rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2
if ((extenc != Qundef || intenc != Qundef) && !NIL_P(encoding)) {
if (!NIL_P(ruby_verbose)) {
int idx = rb_to_encoding_index(encoding);
- rb_warn("Ignoring encoding parameter '%s': %s_encoding is used",
- idx < 0 ? StringValueCStr(encoding) : rb_enc_name(rb_enc_from_index(idx)),
- extenc == Qundef ? "internal" : "external");
+ if (idx >= 0) encoding = rb_enc_from_encoding(rb_enc_from_index(idx));
+ rb_warn("Ignoring encoding parameter '%"PRIsVALUE"': %s_encoding is used",
+ encoding, extenc == Qundef ? "internal" : "external");
}
encoding = Qnil;
}
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index e9e6a1cf83a..7f54762ebea 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -312,6 +312,17 @@ EOT
}
end
+ def test_ignored_encoding_option
+ enc = "\u{30a8 30f3 30b3 30fc 30c7 30a3 30f3 30b0}"
+ pattern = /#{enc}/
+ assert_warning(pattern) {
+ open(IO::NULL, external_encoding: "us-ascii", encoding: enc)
+ }
+ assert_warning(pattern) {
+ open(IO::NULL, internal_encoding: "us-ascii", encoding: enc)
+ }
+ end
+
def test_io_new_enc
with_tmpdir {
generate_file("tmp", "\xa1")