summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-15 06:14:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-15 06:14:16 +0000
commit9fff5f0fabb50ab0d46034d6c1b9dcc4447a8a66 (patch)
tree98f424f4c8015a380efb002f2a7ad403f320d366 /io.c
parent6069202867ab9016aaf66301468d5f4c64b3b028 (diff)
* io.c (io_encoding_set): get rid of parsing non-ascii string, and
refine messages for invalid name encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/io.c b/io.c
index ccec1601dc..7ef11920ed 100644
--- a/io.c
+++ b/io.c
@@ -7500,8 +7500,7 @@ io_encoding_set(rb_io_t *fptr, VALUE v1, VALUE v2, VALUE opt)
enc2 = rb_to_encoding(v1);
tmp = rb_check_string_type(v2);
if (!NIL_P(tmp)) {
- char *p = StringValueCStr(tmp);
- if (*p == '-' && *(p+1) == '\0') {
+ if (RSTRING_LEN(tmp) == 1 && RSTRING_PTR(tmp)[0] == '-') {
/* Special case - "-" => no transcoding */
enc = enc2;
enc2 = NULL;
@@ -7526,8 +7525,8 @@ io_encoding_set(rb_io_t *fptr, VALUE v1, VALUE v2, VALUE opt)
}
else {
tmp = rb_check_string_type(v1);
- if (!NIL_P(tmp)) {
- parse_mode_enc(StringValueCStr(tmp), &enc, &enc2);
+ if (!NIL_P(tmp) && rb_enc_asciicompat(rb_enc_get(tmp))) {
+ parse_mode_enc(RSTRING_PTR(tmp), &enc, &enc2);
ecflags = rb_econv_prepare_opts(opt, &ecopts);
}
else {