ruby-changes:3713
From: ko1@a...
Date: Thu, 24 Jan 2008 11:17:44 +0900 (JST)
Subject: [ruby-changes:3713] akr - Ruby:r15202 (trunk): * string.c (rb_enc_cr_str_buf_cat): ASCII incompatible encoding is
akr 2008-01-24 11:17:26 +0900 (Thu, 24 Jan 2008)
New Revision: 15202
Modified files:
trunk/ChangeLog
trunk/string.c
trunk/test/ruby/test_utf16.rb
Log:
* string.c (rb_enc_cr_str_buf_cat): ASCII incompatible encoding is
not compatible with any other encoding.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=15202&r2=15201&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15202&r2=15201&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_utf16.rb?r1=15202&r2=15201&diff_format=u
Index: ChangeLog
===================================================================
--- ChangeLog (revision 15201)
+++ ChangeLog (revision 15202)
@@ -1,3 +1,8 @@
+Thu Jan 24 11:14:56 2008 Tanaka Akira <akr@f...>
+
+ * string.c (rb_enc_cr_str_buf_cat): ASCII incompatible encoding is
+ not compatible with any other encoding.
+
Thu Jan 24 07:34:34 2008 NARUSE, Yui <naruse@r...>
* parse.y (STR_NEW0): set encoding as US-ASCII.
Index: string.c
===================================================================
--- string.c (revision 15201)
+++ string.c (revision 15202)
@@ -1140,8 +1140,13 @@
}
}
else {
+ rb_encoding *str_enc = rb_enc_from_index(str_encindex);
+ rb_encoding *ptr_enc = rb_enc_from_index(ptr_encindex);
+ if (!rb_enc_asciicompat(str_enc) || !rb_enc_asciicompat(ptr_enc)) {
+ goto incompatible;
+ }
if (ptr_cr == ENC_CODERANGE_UNKNOWN) {
- ptr_cr = coderange_scan(ptr, len, rb_enc_from_index(ptr_encindex));
+ ptr_cr = coderange_scan(ptr, len, ptr_enc);
}
if (str_cr == ENC_CODERANGE_UNKNOWN) {
if (str_a8 || ptr_cr != ENC_CODERANGE_7BIT) {
@@ -1155,6 +1160,7 @@
if (str_encindex != ptr_encindex &&
str_cr != ENC_CODERANGE_7BIT &&
ptr_cr != ENC_CODERANGE_7BIT) {
+incompatible:
rb_raise(rb_eArgError, "append incompatible encoding strings: %s and %s",
rb_enc_name(rb_enc_from_index(str_encindex)),
rb_enc_name(rb_enc_from_index(ptr_encindex)));
Index: test/ruby/test_utf16.rb
===================================================================
--- test/ruby/test_utf16.rb (revision 15201)
+++ test/ruby/test_utf16.rb (revision 15202)
@@ -103,4 +103,12 @@
def test_slice!
enccall("aa".force_encoding("UTF-16BE"), :slice!, -1)
end
+
+ def test_concat
+ s1 = ""
+ s2 = "aa".force_encoding("utf-16be")
+ assert_raise(ArgumentError, "#{encdump s1} << #{encdump s2}") {
+ s1 << s2
+ }
+ end
end
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/