mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* encoding.c (rb_enc_compatible): fix segv on symbols.
[ruby-core:42204] [Bug #5921] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c8f98a75d8
commit
b1428ace6b
3 changed files with 25 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Jan 21 21:51:19 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* encoding.c (rb_enc_compatible): fix segv on symbols.
|
||||||
|
[ruby-core:42204] [Bug #5921]
|
||||||
|
|
||||||
Sat Jan 21 11:43:45 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Jan 21 11:43:45 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* dir.c (dir_chdir, check_dirname): get rid of optimization-out.
|
* dir.c (dir_chdir, check_dirname): get rid of optimization-out.
|
||||||
|
|
22
encoding.c
22
encoding.c
|
@ -759,6 +759,7 @@ rb_enc_compatible(VALUE str1, VALUE str2)
|
||||||
{
|
{
|
||||||
int idx1, idx2;
|
int idx1, idx2;
|
||||||
rb_encoding *enc1, *enc2;
|
rb_encoding *enc1, *enc2;
|
||||||
|
int isstr1, isstr2;
|
||||||
|
|
||||||
idx1 = rb_enc_get_index(str1);
|
idx1 = rb_enc_get_index(str1);
|
||||||
idx2 = rb_enc_get_index(str2);
|
idx2 = rb_enc_get_index(str2);
|
||||||
|
@ -772,33 +773,38 @@ rb_enc_compatible(VALUE str1, VALUE str2)
|
||||||
enc1 = rb_enc_from_index(idx1);
|
enc1 = rb_enc_from_index(idx1);
|
||||||
enc2 = rb_enc_from_index(idx2);
|
enc2 = rb_enc_from_index(idx2);
|
||||||
|
|
||||||
if (BUILTIN_TYPE(str2) == T_STRING && RSTRING_LEN(str2) == 0)
|
isstr2 = RB_TYPE_P(str2, T_STRING);
|
||||||
|
if (isstr2 && RSTRING_LEN(str2) == 0)
|
||||||
return enc1;
|
return enc1;
|
||||||
if (BUILTIN_TYPE(str1) == T_STRING && RSTRING_LEN(str1) == 0)
|
isstr1 = RB_TYPE_P(str1, T_STRING);
|
||||||
|
if (isstr1 && RSTRING_LEN(str1) == 0)
|
||||||
return (rb_enc_asciicompat(enc1) && rb_enc_str_asciionly_p(str2)) ? enc1 : enc2;
|
return (rb_enc_asciicompat(enc1) && rb_enc_str_asciionly_p(str2)) ? enc1 : enc2;
|
||||||
if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2)) {
|
if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* objects whose encoding is the same of contents */
|
/* objects whose encoding is the same of contents */
|
||||||
if (BUILTIN_TYPE(str2) != T_STRING && idx2 == ENCINDEX_US_ASCII)
|
if (!isstr2 && idx2 == ENCINDEX_US_ASCII)
|
||||||
return enc1;
|
return enc1;
|
||||||
if (BUILTIN_TYPE(str1) != T_STRING && idx1 == ENCINDEX_US_ASCII)
|
if (!isstr1 && idx1 == ENCINDEX_US_ASCII)
|
||||||
return enc2;
|
return enc2;
|
||||||
|
|
||||||
if (BUILTIN_TYPE(str1) != T_STRING) {
|
if (!isstr1) {
|
||||||
VALUE tmp = str1;
|
VALUE tmp = str1;
|
||||||
int idx0 = idx1;
|
int idx0 = idx1;
|
||||||
str1 = str2;
|
str1 = str2;
|
||||||
str2 = tmp;
|
str2 = tmp;
|
||||||
idx1 = idx2;
|
idx1 = idx2;
|
||||||
idx2 = idx0;
|
idx2 = idx0;
|
||||||
|
idx0 = isstr1;
|
||||||
|
isstr1 = isstr2;
|
||||||
|
isstr2 = idx0;
|
||||||
}
|
}
|
||||||
if (BUILTIN_TYPE(str1) == T_STRING) {
|
if (isstr1) {
|
||||||
int cr1, cr2;
|
int cr1, cr2;
|
||||||
|
|
||||||
cr1 = rb_enc_str_coderange(str1);
|
cr1 = rb_enc_str_coderange(str1);
|
||||||
if (BUILTIN_TYPE(str2) == T_STRING) {
|
if (isstr2) {
|
||||||
cr2 = rb_enc_str_coderange(str2);
|
cr2 = rb_enc_str_coderange(str2);
|
||||||
if (cr1 != cr2) {
|
if (cr1 != cr2) {
|
||||||
/* may need to handle ENC_CODERANGE_BROKEN */
|
/* may need to handle ENC_CODERANGE_BROKEN */
|
||||||
|
@ -1083,7 +1089,7 @@ enc_find(VALUE klass, VALUE enc)
|
||||||
*
|
*
|
||||||
* If the objects are non-strings their encodings are compatible when they
|
* If the objects are non-strings their encodings are compatible when they
|
||||||
* have an encoding and:
|
* have an encoding and:
|
||||||
* * Either encoding is US ASCII compatible
|
* * Either encoding is US-ASCII compatible
|
||||||
* * One of the encodings is a 7-bit encoding
|
* * One of the encodings is a 7-bit encoding
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -104,4 +104,10 @@ class TestEncoding < Test::Unit::TestCase
|
||||||
bug5279 = '[ruby-dev:44469]'
|
bug5279 = '[ruby-dev:44469]'
|
||||||
assert_ruby_status([], '$SAFE=4; "a".encode("utf-16be")', bug5279)
|
assert_ruby_status([], '$SAFE=4; "a".encode("utf-16be")', bug5279)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_compatible_p
|
||||||
|
ua = "abc".force_encoding(Encoding::UTF_8)
|
||||||
|
assert_equal(Encoding::UTF_8, Encoding.compatible?(ua, :abc))
|
||||||
|
assert_equal(nil, Encoding.compatible?(ua, 1))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue