mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
6069202867
commit
9fff5f0fab
3 changed files with 27 additions and 26 deletions
|
@ -1,4 +1,7 @@
|
||||||
Thu Oct 15 14:57:58 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Oct 15 15:14:15 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (io_encoding_set): get rid of parsing non-ascii string, and
|
||||||
|
refine messages for invalid name encoding.
|
||||||
|
|
||||||
* io.c (io_reopen): unread current buffer before telling the
|
* io.c (io_reopen): unread current buffer before telling the
|
||||||
position, for the case of reopening same file. [ruby-dev:39479]
|
position, for the case of reopening same file. [ruby-dev:39479]
|
||||||
|
|
7
io.c
7
io.c
|
@ -7500,8 +7500,7 @@ io_encoding_set(rb_io_t *fptr, VALUE v1, VALUE v2, VALUE opt)
|
||||||
enc2 = rb_to_encoding(v1);
|
enc2 = rb_to_encoding(v1);
|
||||||
tmp = rb_check_string_type(v2);
|
tmp = rb_check_string_type(v2);
|
||||||
if (!NIL_P(tmp)) {
|
if (!NIL_P(tmp)) {
|
||||||
char *p = StringValueCStr(tmp);
|
if (RSTRING_LEN(tmp) == 1 && RSTRING_PTR(tmp)[0] == '-') {
|
||||||
if (*p == '-' && *(p+1) == '\0') {
|
|
||||||
/* Special case - "-" => no transcoding */
|
/* Special case - "-" => no transcoding */
|
||||||
enc = enc2;
|
enc = enc2;
|
||||||
enc2 = NULL;
|
enc2 = NULL;
|
||||||
|
@ -7526,8 +7525,8 @@ io_encoding_set(rb_io_t *fptr, VALUE v1, VALUE v2, VALUE opt)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tmp = rb_check_string_type(v1);
|
tmp = rb_check_string_type(v1);
|
||||||
if (!NIL_P(tmp)) {
|
if (!NIL_P(tmp) && rb_enc_asciicompat(rb_enc_get(tmp))) {
|
||||||
parse_mode_enc(StringValueCStr(tmp), &enc, &enc2);
|
parse_mode_enc(RSTRING_PTR(tmp), &enc, &enc2);
|
||||||
ecflags = rb_econv_prepare_opts(opt, &ecopts);
|
ecflags = rb_econv_prepare_opts(opt, &ecopts);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -220,33 +220,27 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_s_pipe_invalid
|
def test_s_pipe_invalid
|
||||||
r, w = IO.pipe("utf-8", "euc-jp", :invalid=>:replace)
|
with_pipe("utf-8", "euc-jp", :invalid=>:replace) {|r, w|
|
||||||
w << "\x80"
|
w << "\x80"
|
||||||
w.close
|
w.close
|
||||||
assert_equal("?", r.read)
|
assert_equal("?", r.read)
|
||||||
ensure
|
}
|
||||||
r.close if r && !r.closed?
|
|
||||||
w.close if w && !w.closed?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_s_pipe_undef
|
def test_s_pipe_undef
|
||||||
r, w = IO.pipe("utf-8:euc-jp", :undef=>:replace)
|
with_pipe("utf-8:euc-jp", :undef=>:replace) {|r, w|
|
||||||
w << "\ufffd"
|
w << "\ufffd"
|
||||||
w.close
|
w.close
|
||||||
assert_equal("?", r.read)
|
assert_equal("?", r.read)
|
||||||
ensure
|
}
|
||||||
r.close if r && !r.closed?
|
|
||||||
w.close if w && !w.closed?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_s_pipe_undef_replace_string
|
def test_s_pipe_undef_replace_string
|
||||||
r, w = IO.pipe("utf-8:euc-jp", :undef=>:replace, :replace=>"X")
|
with_pipe("utf-8:euc-jp", :undef=>:replace, :replace=>"X") {|r, w|
|
||||||
w << "\ufffd"
|
w << "\ufffd"
|
||||||
w.close
|
w.close
|
||||||
assert_equal("X", r.read)
|
assert_equal("X", r.read)
|
||||||
ensure
|
}
|
||||||
r.close if r && !r.closed?
|
|
||||||
w.close if w && !w.closed?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dup
|
def test_dup
|
||||||
|
@ -572,6 +566,11 @@ EOT
|
||||||
assert_equal(eucjp, r.read)
|
assert_equal(eucjp, r.read)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e = assert_raise(ArgumentError) {with_pipe("UTF-8", "UTF-8".encode("UTF-32BE")) {}}
|
||||||
|
assert_match(/invalid name encoding/, e.message)
|
||||||
|
e = assert_raise(ArgumentError) {with_pipe("UTF-8".encode("UTF-32BE")) {}}
|
||||||
|
assert_match(/invalid name encoding/, e.message)
|
||||||
|
|
||||||
ENCS.each {|enc|
|
ENCS.each {|enc|
|
||||||
with_pipe(enc) {|r, w|
|
with_pipe(enc) {|r, w|
|
||||||
w << "\xc2\xa1"
|
w << "\xc2\xa1"
|
||||||
|
|
Loading…
Reference in a new issue