Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix fallback convertion
  • Loading branch information
rust committed Jul 2, 2012
1 parent 7abe03f commit ef4e2dd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/jpmobile/emoticon.rb
Expand Up @@ -141,6 +141,7 @@ def self.external_to_unicodecr_google(str)
def self.unicodecr_to_external(str, conversion_table=nil, to_sjis=true)
str.gsub(/&#x([0-9a-f]{4});/i) do |match|
unicode = $1.scanf("%x").first

if conversion_table
converted = conversion_table[unicode] # キャリア間変換
else
Expand All @@ -149,6 +150,8 @@ def self.unicodecr_to_external(str, conversion_table=nil, to_sjis=true)

# 携帯側エンコーディングに変換する
case converted
when 0x3013
'〓'
when Integer
# 変換先がUnicodeで指定されている。つまり対応する絵文字がある。
if sjis = UNICODE_TO_SJIS[converted]
Expand All @@ -163,7 +166,11 @@ def self.unicodecr_to_external(str, conversion_table=nil, to_sjis=true)
# PCで〓を表示する場合
[GETA].pack("U")
elsif UNICODE_EMOTICONS.include?(converted) or GOOGLE_EMOTICONS.include?(converted)
[converted].pack('U*')
if unicode == GETA
[GETA].pack("U")
else
[converted].pack('U*')
end
else
# キャリア変換テーブルに指定されていたUnicodeに対応する
# 携帯側エンコーディングが見つからない(変換テーブルの不備の可能性あり)。
Expand Down
20 changes: 20 additions & 0 deletions spec/rack/jpmobile/emoticon_spec.rb
Expand Up @@ -301,6 +301,11 @@
req.params['q'].should == [0xf04a].pack("U")
response_body(res).should == [0xe04a].pack('U')
end

it 'should not convert 〓' do
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2]
response_body(response).should == '〓'
end
end

context 'upper iOS 5' do
Expand Down Expand Up @@ -333,6 +338,11 @@
req.params['q'].should == [0x26C5].pack("U")
response_body(res).should == [0x26C5].pack('U')
end

it 'should not convert 〓' do
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2]
response_body(response).should == '〓'
end
end
end

Expand Down Expand Up @@ -370,6 +380,11 @@
req.params['q'].should == [0xFE00F].pack("U")
response_body(res).should == [0xFE00F].pack('U')
end

it 'should not convert 〓' do
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2]
response_body(response).should == '〓'
end
end

context 'tablet' do
Expand Down Expand Up @@ -400,6 +415,11 @@
req.params['q'].should == [0xFE00F].pack("U")
response_body(res).should == [0xFE00F].pack('U')
end

it 'should not convert 〓' do
response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2]
response_body(response).should == '〓'
end
end
end
end
16 changes: 16 additions & 0 deletions spec/unit/emoticon_spec.rb
Expand Up @@ -43,6 +43,10 @@
Jpmobile::Emoticon.unicodecr_to_external("", Jpmobile::Emoticon::CONVERSION_TABLE_TO_UNICODE_EMOTICON, false).should == [0x1F466].pack('U')
end

it 'should not convert 〓' do
Jpmobile::Emoticon.unicodecr_to_external("〓", Jpmobile::Emoticon::CONVERSION_TABLE_TO_UNICODE_EMOTICON, false).should == '〓'
end

it 'should convert docomo unicodecr to Google emoticon' do
Jpmobile::Emoticon.unicodecr_to_external("", Jpmobile::Emoticon::CONVERSION_TABLE_TO_GOOGLE_EMOTICON, false).should == [0xFE000].pack('U')
end
Expand All @@ -54,6 +58,10 @@
it 'should convert Softbank unicodecr to Google emoticon' do
Jpmobile::Emoticon.unicodecr_to_external("", Jpmobile::Emoticon::CONVERSION_TABLE_TO_GOOGLE_EMOTICON, false).should == [0xFE19B].pack('U')
end

it 'should not convert 〓' do
Jpmobile::Emoticon.unicodecr_to_external("〓", Jpmobile::Emoticon::CONVERSION_TABLE_TO_GOOGLE_EMOTICON, false).should == '〓'
end
end

describe "unicodecr_to_utf8" do
Expand Down Expand Up @@ -103,6 +111,10 @@
it 'should convert iPhone Unicode emoticon to multi SoftBank emoticons' do
Jpmobile::Emoticon::external_to_unicodecr_unicode60("\342\233\205").should == ","
end

it 'should not convert 〓' do
Jpmobile::Emoticon::external_to_unicodecr_unicode60('〓').should == "〓"
end
end

context 'at Android emoticon' do
Expand All @@ -113,6 +125,10 @@
it 'should convert Android Google Unicode emoticon to multi Docomo emoticon' do
Jpmobile::Emoticon::external_to_unicodecr_google("\363\276\200\217").should == ""
end

it 'should not convert 〓' do
Jpmobile::Emoticon::external_to_unicodecr_google('〓').should == "〓"
end
end
end

Expand Down

0 comments on commit ef4e2dd

Please sign in to comment.