From 628420db638ccbc857601254ca547bc81d667e72 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 9 Sep 2008 14:56:55 +0000 Subject: * io.c (io_fwrite): raise an error if ASCII incompatible string written for text mode IO without encoding conversion. (rb_io_extract_modeenc): binmode requirement changed. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'io.c') diff --git a/io.c b/io.c index cfe84cc7e..ef2cdab2c 100644 --- a/io.c +++ b/io.c @@ -756,6 +756,10 @@ io_fwrite(VALUE str, rb_io_t *fptr) if (fptr->writeconv) { if (!NIL_P(fptr->writeconv_stateless)) common_encoding = fptr->writeconv_stateless; + else if (!rb_enc_asciicompat(rb_enc_get(str))) { + rb_raise(rb_eArgError, "ASCII incompatible string written for text mode IO without encoding conversion: %s", + rb_enc_name(rb_enc_get(str))); + } } else { if (fptr->encs.enc2) @@ -3908,7 +3912,10 @@ rb_io_extract_modeenc(VALUE *vmode_p, VALUE opthash, if ((fmode & FMODE_BINMODE) && (fmode & FMODE_TEXTMODE)) rb_raise(rb_eArgError, "both textmode and binmode specified"); - if (enc && !rb_enc_asciicompat(enc) && !(fmode & FMODE_BINMODE)) + if ((fmode & FMODE_READABLE) && + !enc2 && + !(fmode & FMODE_BINMODE) && + !rb_enc_asciicompat(enc ? enc : rb_default_external_encoding())) rb_raise(rb_eArgError, "ASCII incompatible encoding needs binmode"); *vmode_p = vmode; -- cgit