mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 21:14:23 +02: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:
parent
7a4f70463d
commit
ffa153f282
2 changed files with 14 additions and 3 deletions
6
io.c
6
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 ((extenc != Qundef || intenc != Qundef) && !NIL_P(encoding)) {
|
||||||
if (!NIL_P(ruby_verbose)) {
|
if (!NIL_P(ruby_verbose)) {
|
||||||
int idx = rb_to_encoding_index(encoding);
|
int idx = rb_to_encoding_index(encoding);
|
||||||
rb_warn("Ignoring encoding parameter '%s': %s_encoding is used",
|
if (idx >= 0) encoding = rb_enc_from_encoding(rb_enc_from_index(idx));
|
||||||
idx < 0 ? StringValueCStr(encoding) : rb_enc_name(rb_enc_from_index(idx)),
|
rb_warn("Ignoring encoding parameter '%"PRIsVALUE"': %s_encoding is used",
|
||||||
extenc == Qundef ? "internal" : "external");
|
encoding, extenc == Qundef ? "internal" : "external");
|
||||||
}
|
}
|
||||||
encoding = Qnil;
|
encoding = Qnil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -312,6 +312,17 @@ EOT
|
||||||
}
|
}
|
||||||
end
|
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
|
def test_io_new_enc
|
||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
generate_file("tmp", "\xa1")
|
generate_file("tmp", "\xa1")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue