Skip to content

Commit

Permalink
* encoding.c (rb_enc_compatible): If a string is empty and
Browse files Browse the repository at this point in the history
  other's encoding is US-ASCII, returns the empty string's encoding.
  [ruby-list:46274]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Aug 11, 2009
1 parent 8b83fc2 commit e666111
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Wed Aug 12 07:41:31 2009 NARUSE, Yui <[email protected]>

* encoding.c (rb_enc_compatible): If a string is empty and
other's encoding is US-ASCII, returns the empty string's encoding.
[ruby-list:46274]

Wed Aug 12 07:38:12 2009 NARUSE, Yui <[email protected]>

* encoding.c (is_data_encoding): fix condition.
Expand Down
4 changes: 2 additions & 2 deletions encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,9 @@ rb_enc_compatible(VALUE str1, VALUE str2)
enc2 = rb_enc_from_index(idx2);

if (TYPE(str2) == T_STRING && RSTRING_LEN(str2) == 0)
return enc1;
return (idx1 == ENCINDEX_US_ASCII && rb_enc_asciicompat(enc2)) ? enc2 : enc1;
if (TYPE(str1) == T_STRING && RSTRING_LEN(str1) == 0)
return enc2;
return (idx2 == ENCINDEX_US_ASCII && rb_enc_asciicompat(enc1)) ? enc1 : enc2;
if (!rb_enc_asciicompat(enc1) || !rb_enc_asciicompat(enc2)) {
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions test/ruby/test_m17n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def assert_encoding(encname, actual, message=nil)
end

module AESU
def ua(str) str.dup.force_encoding("US-ASCII") end
def a(str) str.dup.force_encoding("ASCII-8BIT") end
def e(str) str.dup.force_encoding("EUC-JP") end
def s(str) str.dup.force_encoding("Windows-31J") end
Expand Down Expand Up @@ -1300,6 +1301,7 @@ def test_setbyte

def test_compatible
assert_nil Encoding.compatible?("",0)
assert_equal(Encoding::UTF_8, Encoding.compatible?(u(""), ua("abc")))
assert_equal(Encoding::UTF_8, Encoding.compatible?(Encoding::UTF_8, Encoding::UTF_8))
assert_equal(Encoding::UTF_8, Encoding.compatible?(Encoding::UTF_8, Encoding::US_ASCII))
assert_equal(Encoding::ASCII_8BIT,
Expand Down

0 comments on commit e666111

Please sign in to comment.