1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

io.c: preserve encodings

* io.c (rb_io_extract_encoding_option): preserve encodings in
  warning messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-08-28 05:55:22 +00:00
parent 7a4f70463d
commit ffa153f282
2 changed files with 14 additions and 3 deletions

6
io.c
View file

@ -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;
}

View file

@ -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")