diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-15 06:14:16 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-15 06:14:16 +0000 |
| commit | 498d8031e23234a3cf8aebd185128ac7bcc35522 (patch) | |
| tree | 98f424f4c8015a380efb002f2a7ad403f320d366 /io.c | |
| parent | e2f40d88894700b532d7c187aef3e2a5e8be1d5a (diff) | |
| download | ruby-498d8031e23234a3cf8aebd185128ac7bcc35522.tar.gz ruby-498d8031e23234a3cf8aebd185128ac7bcc35522.tar.xz ruby-498d8031e23234a3cf8aebd185128ac7bcc35522.zip | |
* io.c (io_encoding_set): get rid of parsing non-ascii string, and
refine messages for invalid name encoding.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
| -rw-r--r-- | io.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -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 { |
