Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* io.c (io_encoding_set): always warn if external encoding and internal

  encoding are identical. [ruby-core:40727] [Bug #5568]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit db83618d2c49cbab8b78e31ecf5a8979895bc5d6 1 parent 272d72e
NARUSE, Yui nurse authored
Showing with 43 additions and 1 deletion.
  1. +5 −0 ChangeLog
  2. +12 −1 io.c
  3. +26 −0 test/ruby/test_io_m17n.rb
5 ChangeLog
View
@@ -1,3 +1,8 @@
+Tue Mar 13 12:37:53 2012 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * io.c (io_encoding_set): always warn if external encoding and internal
+ encoding are identical. [ruby-core:40727] [Bug #5568]
+
Tue Mar 13 12:37:03 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
Bug #5350
13 io.c
View
@@ -8743,11 +8743,22 @@ io_encoding_set(rb_io_t *fptr, VALUE v1, VALUE v2, VALUE opt)
enc = find_encoding(v2);
if (enc == enc2) {
/* Special case - "-" => no transcoding */
+ VALUE tmp1 = rb_check_string_type(v1);
+ rb_warn("Ignoring internal encoding %s: it is identical to external encoding %s",
+ StringValueCStr(tmp), NIL_P(tmp1) ? rb_enc_name(enc) : StringValueCStr(tmp1));
enc2 = NULL;
}
}
- else
+ else {
enc = find_encoding(v2);
+ if (enc == enc2) {
+ /* Special case - "-" => no transcoding */
+ VALUE tmp1 = rb_check_string_type(v1);
+ rb_warn("Ignoring internal encoding %s: it is identical to external encoding %s",
+ rb_enc_name(enc), NIL_P(tmp1) ? rb_enc_name(enc) : StringValueCStr(tmp1));
+ enc2 = NULL;
+ }
+ }
SET_UNIVERSAL_NEWLINE_DECORATOR_IF_ENC2(enc2, ecflags);
ecflags = rb_econv_prepare_options(opt, &ecopts, ecflags);
}
26 test/ruby/test_io_m17n.rb
View
@@ -984,6 +984,32 @@ def test_set_encoding_invalid
end)
end
+ def test_set_encoding_identical
+ bug5568 = '[ruby-core:40727]'
+ open(__FILE__, "r") do |f|
+ assert_warn(/Ignoring internal encoding euc-jp: it is identical to external encoding eucjp/, bug5568) {
+ f.set_encoding("eucjp:euc-jp")
+ }
+ assert_warn(/Ignoring internal encoding euc-jp: it is identical to external encoding eucjp/, bug5568) {
+ f.set_encoding("eucjp", "euc-jp")
+ }
+ assert_warn(/Ignoring internal encoding euc-jp: it is identical to external encoding EUC-JP/, bug5568) {
+ f.set_encoding(Encoding::EUC_JP, "euc-jp")
+ }
+ assert_warn(/Ignoring internal encoding EUC-JP: it is identical to external encoding eucjp/, bug5568) {
+ f.set_encoding("eucjp", Encoding::EUC_JP)
+ }
+ assert_warn(/Ignoring internal encoding EUC-JP: it is identical to external encoding EUC-JP/, bug5568) {
+ f.set_encoding(Encoding::EUC_JP, Encoding::EUC_JP)
+ }
+ nonstr = Object.new
+ def nonstr.to_str; "eucjp"; end
+ assert_warn(/Ignoring internal encoding eucjp: it is identical to external encoding eucjp/, bug5568) {
+ f.set_encoding(nonstr, nonstr)
+ }
+ end
+ end
+
def test_set_encoding_undef
pipe(proc do |w|
w << "\ufffd"
Please sign in to comment.
Something went wrong with that request. Please try again.