* transcode.c (rb_econv_open): fail for ASCII incompatible with
newline conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d4384f1230
commit
0be34e2a49
@ -1,3 +1,8 @@
|
||||
Sat Sep 6 07:27:00 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* transcode.c (rb_econv_open): fail for ASCII incompatible with
|
||||
newline conversion.
|
||||
|
||||
Sat Sep 6 07:24:49 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (rb_io_extract_modeenc): raise an error for ASCII incompatible
|
||||
|
@ -54,6 +54,28 @@ class TestEncodingConverter < Test::Unit::TestCase
|
||||
assert(!encoding_list.include?(name2))
|
||||
end
|
||||
|
||||
def test_newline_converter_with_ascii_incompatible
|
||||
assert_raise(Encoding::NoConverter) {
|
||||
Encoding::Converter.new("UTF-8", "UTF-16BE", Encoding::Converter::UNIVERSAL_NEWLINE_DECODER)
|
||||
}
|
||||
assert_raise(Encoding::NoConverter) {
|
||||
Encoding::Converter.new("UTF-16BE", "UTF-8", Encoding::Converter::CRLF_NEWLINE_ENCODER)
|
||||
}
|
||||
assert_raise(Encoding::NoConverter) {
|
||||
Encoding::Converter.new("UTF-16BE", "UTF-8", Encoding::Converter::CR_NEWLINE_ENCODER)
|
||||
}
|
||||
|
||||
assert_nothing_raised {
|
||||
Encoding::Converter.new("UTF-16BE", "UTF-8", Encoding::Converter::UNIVERSAL_NEWLINE_DECODER)
|
||||
}
|
||||
assert_nothing_raised {
|
||||
Encoding::Converter.new("UTF-8", "UTF-16BE", Encoding::Converter::CRLF_NEWLINE_ENCODER)
|
||||
}
|
||||
assert_nothing_raised {
|
||||
Encoding::Converter.new("UTF-8", "UTF-16BE", Encoding::Converter::CR_NEWLINE_ENCODER)
|
||||
}
|
||||
end
|
||||
|
||||
def test_get_encoding
|
||||
ec = Encoding::Converter.new("UTF-8", "EUC-JP")
|
||||
assert_equal(Encoding::UTF_8, ec.source_encoding)
|
||||
|
13
transcode.c
13
transcode.c
@ -913,6 +913,19 @@ rb_econv_open(const char *sname, const char *dname, int ecflags)
|
||||
}
|
||||
|
||||
num_additional = 0;
|
||||
|
||||
if (*sname && (!senc || !rb_enc_asciicompat(senc)) &&
|
||||
(ecflags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER))) {
|
||||
xfree(entries);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*dname && (!denc || !rb_enc_asciicompat(denc)) &&
|
||||
(ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER))) {
|
||||
xfree(entries);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((!*sname || (senc && rb_enc_asciicompat(senc))) &&
|
||||
(ecflags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER))) {
|
||||
const char *name = (ecflags & ECONV_CRLF_NEWLINE_ENCODER) ? "crlf_newline" : "cr_newline";
|
||||
|
Loading…
x
Reference in New Issue
Block a user