jpmobile 1.0.12 → 2.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/Gemfile +3 -3
  2. data/README.rdoc +2 -14
  3. data/Rakefile +0 -1
  4. data/VERSION.yml +4 -4
  5. data/jpmobile.gemspec +2 -1
  6. data/lib/jpmobile.rb +1 -15
  7. data/lib/jpmobile/docomo_guid.rb +1 -1
  8. data/lib/jpmobile/emoticon.rb +3 -119
  9. data/lib/jpmobile/emoticon/z_combine.rb +1 -17
  10. data/lib/jpmobile/filter.rb +1 -6
  11. data/lib/jpmobile/helpers.rb +1 -1
  12. data/lib/jpmobile/mail.rb +27 -196
  13. data/lib/jpmobile/mailer.rb +1 -7
  14. data/lib/jpmobile/mobile/abstract_mobile.rb +36 -94
  15. data/lib/jpmobile/mobile/android.rb +0 -2
  16. data/lib/jpmobile/mobile/au.rb +0 -4
  17. data/lib/jpmobile/mobile/docomo.rb +0 -8
  18. data/lib/jpmobile/mobile/iphone.rb +15 -1
  19. data/lib/jpmobile/mobile/smart_phone.rb +0 -10
  20. data/lib/jpmobile/mobile/softbank.rb +0 -8
  21. data/lib/jpmobile/rack.rb +1 -6
  22. data/lib/jpmobile/rack/filter.rb +1 -7
  23. data/lib/jpmobile/rack/params_filter.rb +2 -2
  24. data/lib/jpmobile/rails.rb +1 -1
  25. data/lib/jpmobile/resolver.rb +2 -5
  26. data/lib/jpmobile/trans_sid.rb +1 -26
  27. data/lib/jpmobile/util.rb +11 -82
  28. data/lib/tasks/jpmobile_tasks.rake +1 -1
  29. data/spec/rack/jpmobile/emoticon_spec.rb +0 -223
  30. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +1 -5
  31. data/spec/rack/jpmobile/softbank_spec.rb +1 -1
  32. data/spec/unit/emoticon_spec.rb +0 -64
  33. data/spec/unit/encoding_spec.rb +2 -2
  34. data/spec/unit/mail_spec.rb +2 -159
  35. data/spec/unit/receive_mail_spec.rb +5 -51
  36. data/spec/unit/spec_helper.rb +1 -1
  37. data/spec/unit/util_spec.rb +3 -62
  38. data/test/rails/overrides/Gemfile +1 -1
  39. data/test/rails/overrides/app/controllers/filter_controller_base.rb +0 -3
  40. data/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb +0 -3
  41. data/test/rails/overrides/app/controllers/template_path_controller.rb +0 -12
  42. data/test/rails/overrides/app/{mailers → models}/mobile_mailer.rb +1 -7
  43. data/test/rails/overrides/app/{mailers → models}/normal_mailer.rb +0 -0
  44. data/test/rails/overrides/spec/{mailers → models}/mobile_mailer_spec.rb +1 -18
  45. data/test/rails/overrides/spec/{mailers → models}/normal_mailer_spec.rb +0 -0
  46. data/test/rails/overrides/spec/requests/filter_spec.rb +0 -18
  47. data/test/rails/overrides/spec/requests/template_path_spec.rb +0 -72
  48. data/test/rails/overrides/spec/spec_helper.rb +1 -1
  49. data/test/sinatra/guestbook.rb +7 -8
  50. data/test/sinatra/test/filter_test.rb +0 -10
  51. metadata +169 -296
  52. data/lib/jpmobile/emoticon/google.rb +0 -2421
  53. data/lib/jpmobile/emoticon/unicode.rb +0 -2253
  54. data/lib/jpmobile/mobile/android_tablet.rb +0 -12
  55. data/lib/jpmobile/mobile/black_berry.rb +0 -10
  56. data/lib/jpmobile/mobile/google_emoticon.rb +0 -29
  57. data/lib/jpmobile/mobile/ipad.rb +0 -12
  58. data/lib/jpmobile/mobile/tablet.rb +0 -16
  59. data/lib/jpmobile/mobile/unicode_emoticon.rb +0 -43
  60. data/lib/jpmobile/sinatra.rb +0 -16
  61. data/spec/rack/jpmobile/black_berry_spec.rb +0 -20
  62. data/spec/unit/decorated_mail_spec.rb +0 -76
  63. data/spec/unit/email-fixtures/bounce_with_utf8_part.eml +0 -42
  64. data/spec/unit/email-fixtures/iphone-mail3.eml +0 -56
  65. data/spec/unit/email-fixtures/iphone-message.eml +0 -27
  66. data/spec/unit/email-fixtures/photo.jpg +0 -0
  67. data/spec/unit/mobile/iphone_spec.rb +0 -34
  68. data/test/rails/overrides/app/mailers/decorated_mailer.rb +0 -11
  69. data/test/rails/overrides/app/views/decorated_mailer/deco_mail.html.erb +0 -10
  70. data/test/rails/overrides/app/views/decorated_mailer/deco_mail.text.erb +0 -1
  71. data/test/rails/overrides/app/views/hankaku_input_filter/with_charset.html.erb +0 -1
  72. data/test/rails/overrides/app/views/layouts/with_charset.html.erb +0 -13
  73. data/test/rails/overrides/app/views/template_path/smart_phone_only.html.erb +0 -1
  74. data/test/rails/overrides/app/views/template_path/smart_phone_only_smart_phone.html.erb +0 -1
  75. data/test/rails/overrides/app/views/template_path/with_ipd.html.erb +0 -1
  76. data/test/rails/overrides/app/views/template_path/with_ipd_tablet_ipad.html.erb +0 -1
  77. data/test/rails/overrides/app/views/template_path/with_tblt.html.erb +0 -1
  78. data/test/rails/overrides/app/views/template_path/with_tblt_tablet.html.erb +0 -1
  79. data/test/rails/overrides/spec/fixtures/mobile_mailer/bounced-jp.eml +0 -72
  80. data/test/rails/overrides/spec/fixtures/mobile_mailer/photo.jpg +0 -0
  81. data/test/rails/overrides/spec/mailers/decorated_mailer_spec.rb +0 -44
  82. data/test/sinatra/config.ru +0 -2
  83. data/test/sinatra/views/index.erb +0 -1
  84. data/test/sinatra/views/index_mobile.erb +0 -1
  85. data/tools/e4u_conv.rb +0 -122
data/lib/jpmobile/util.rb CHANGED
@@ -102,11 +102,9 @@ module Jpmobile
102
102
  utf8_str = minus_sign_to_fullwidth_hyphen_minus(utf8_str)
103
103
 
104
104
  if utf8_str.respond_to?(:encode)
105
- utf8_str.
106
- gsub(/(\r\n|\r|\n)/, "\r\n").
107
- encode(SJIS, :undef => :replace, :replace => '?')
105
+ utf8_str.encode(SJIS, :crlf_newline => true,:undef => :replace,:replace => '?')
108
106
  else
109
- NKF.nkf("-m0 -x -W --oc=cp932 --fb-subchar=63", utf8_str).gsub(/(\r\n|\r|\n)/, "\r\n")
107
+ NKF.nkf("-m0 -x -W --oc=cp932 --fb-subchar=63", utf8_str).gsub(/\n/, "\r\n")
110
108
  end
111
109
  end
112
110
 
@@ -114,7 +112,7 @@ module Jpmobile
114
112
  utf8_str = if sjis_str.respond_to?(:encode)
115
113
  sjis_str.encode("UTF-8", :universal_newline => true)
116
114
  else
117
- NKF.nkf("-m0 -x -w --ic=cp932", sjis_str).gsub(/\r\n?/, "\n")
115
+ NKF.nkf("-m0 -x -w --ic=cp932", sjis_str).gsub(/\r\n/, "\n")
118
116
  end
119
117
 
120
118
  # 波ダッシュ対策
@@ -122,15 +120,10 @@ module Jpmobile
122
120
  end
123
121
 
124
122
  def utf8_to_jis(utf8_str)
125
- # 波ダッシュ対策
126
- utf8_str = fullwidth_tilde_to_wavedash(utf8_str)
127
-
128
123
  if utf8_str.respond_to?(:encode)
129
- utf8_str.
130
- gsub(/(\r\n|\r|\n)/, "\r\n").
131
- encode(JIS, :undef => :replace, :replace => '?')
124
+ utf8_str.encode(JIS, :crlf_newline => true)
132
125
  else
133
- NKF.nkf("-m0 -x -Wj --fb-subchar=63", utf8_str).gsub(/(\r\n|\r|\n)/, "\r\n")
126
+ NKF.nkf("-m0 -x -Wj", utf8_str).gsub(/\n/, "\r\n")
134
127
  end
135
128
  end
136
129
 
@@ -138,7 +131,7 @@ module Jpmobile
138
131
  if jis_str.respond_to?(:encode)
139
132
  jis_str.encode(UTF8, :universal_newline => true)
140
133
  else
141
- NKF.nkf("-m0 -x -Jw", jis_str).gsub(/\r\n?/, "\n")
134
+ NKF.nkf("-m0 -x -Jw", jis_str).gsub(/\r\n/, "\n")
142
135
  end
143
136
  end
144
137
 
@@ -187,21 +180,15 @@ module Jpmobile
187
180
  end
188
181
 
189
182
  def jis_string_regexp
190
- Regexp.compile(Regexp.escape(ascii_8bit("\x1b\x24\x42")) + "(.+?)" + Regexp.escape(ascii_8bit("\x1b\x28\x42")))
183
+ Regexp.compile(Regexp.escape(ascii_8bit("\x1b\x24\x42")) + "(.+)" + Regexp.escape(ascii_8bit("\x1b\x28\x42")))
191
184
  end
192
185
 
193
186
  def encode(str, charset)
194
- if (charset.nil? or charset == "" or str.nil? or str == "")
195
- str
196
- elsif utf8?(str) and charset.match(/iso-2022-jp/i)
197
- utf8_to_jis(str)
198
- elsif utf8?(str) and charset.match(/shift_jis/i)
199
- utf8_to_sjis(str)
200
- elsif utf8?(str) and charset.match(/utf-8/i)
201
- str
187
+ if Object.const_defined?(:Encoding)
188
+ (charset.nil? or charset == "" or str.nil? or str == "") ? str : str.encode(charset)
202
189
  else
203
- if Object.const_defined?(:Encoding)
204
- str.encode(charset)
190
+ if str.nil?
191
+ str
205
192
  else
206
193
  case charset
207
194
  when /iso-2022-jp/i
@@ -379,63 +366,5 @@ module Jpmobile
379
366
  end
380
367
 
381
368
  end
382
-
383
- def invert_table(hash)
384
- result = {}
385
- hash.keys.each do |key|
386
- if result[hash[key]]
387
- if !key.kind_of?(Array) and !result[hash[key]].kind_of?(Array) and result[hash[key]] > key
388
- result[hash[key]] = key
389
- end
390
- else
391
- result[hash[key]] = key
392
- end
393
- end
394
- result
395
- end
396
-
397
- def decode(str, encoding, charset)
398
- _str = case encoding
399
- when /quoted-printable/i
400
- str.unpack('M').first.strip
401
- when /base64/i
402
- str.unpack('m').first.strip
403
- else
404
- str
405
- end
406
-
407
- _extract_charset = Jpmobile::Util.extract_charset(_str)
408
- charset = _extract_charset unless _extract_charset.blank? or _extract_charset == charset
409
- Jpmobile::Util.set_encoding(_str, charset)
410
- end
411
-
412
- def check_charset(str, charset)
413
- if Object.const_defined?(:Encoding)
414
- # use NKF.guess
415
- ::Encoding.compatible?(NKF.guess(str), ::Encoding.find(charset))
416
- else
417
- true
418
- end
419
- end
420
-
421
- def correct_encoding(str)
422
- if Object.const_defined?(:Encoding)
423
- if str.encoding != ::Encoding::ASCII_8BIT and NKF.guess(str) != str.encoding
424
- str.force_encoding(NKF.guess(str))
425
- end
426
- else
427
- str = case NKF.guess(str)
428
- when NKF::UTF8
429
- NKF.nkf('-w', str)
430
- when NKF::JIS
431
- pp '1'
432
- NKF.nkf('-j', str)
433
- when NKF::SJIS
434
- NKF.nkf("-s", str)
435
- end
436
- end
437
-
438
- str
439
- end
440
369
  end
441
370
  end
@@ -47,7 +47,7 @@ namespace :test do
47
47
  # setup jpmobile
48
48
  plugin_path = File.join(rails_root, 'vendor', 'plugins', 'jpmobile')
49
49
  FileUtils.mkdir_p(plugin_path)
50
- FileList["*"].exclude("test").exclude("spec").exclude('vendor').each do |file|
50
+ FileList["*"].exclude("test").exclude("spec").each do |file|
51
51
  FileUtils.cp_r(file, plugin_path)
52
52
  end
53
53
 
@@ -7,8 +7,6 @@ describe "絵文字が" do
7
7
  include Jpmobile::Util
8
8
 
9
9
  before(:each) do
10
- Jpmobile.config.smart_phone_emoticon_compatibility = true
11
-
12
10
  @docomo_cr = "";
13
11
  @docomo_utf8 = [0xe63e].pack("U")
14
12
  @docomo_docomopoint = ""
@@ -18,9 +16,6 @@ describe "絵文字が" do
18
16
 
19
17
  @softbank_cr = ""
20
18
  @softbank_utf8 = [0xf04a].pack("U")
21
-
22
- @emoticon_yaml = File.join(File.expand_path(File.dirname(__FILE__)), "../../../tmp/emoticon.yml")
23
- @emoticon_images = File.join(File.expand_path(File.dirname(__FILE__)), "../../../tmp/emoticons")
24
19
  end
25
20
 
26
21
  context "PC のとき" do
@@ -50,59 +45,6 @@ describe "絵文字が" do
50
45
  end
51
46
  end
52
47
 
53
- context "PC で絵文字を変換するとき" do
54
- before(:each) do
55
- unless FileTest.exist?(File.join(File.expand_path(File.dirname(__FILE__)), '../../../tmp/emoticon.yaml')) and
56
- FileTest.directory?(File.join(File.expand_path(File.dirname(__FILE__)), '../../../tmp/emoticons'))
57
- pending "emoticon.yaml and emoticons directory don't exists"
58
- end
59
-
60
- @res = Rack::MockRequest.env_for("/", 'Content-Type' => 'text/html; charset=utf-8')
61
-
62
- Jpmobile::Emoticon.pc_emoticon_yaml = "tmp/emoticon.yaml"
63
- Jpmobile::Emoticon.pc_emoticon_image_path = @path = "tmp/emoticons"
64
- end
65
-
66
- after(:each) do
67
- Jpmobile::Emoticon.pc_emoticon_yaml = nil
68
- Jpmobile::Emoticon.pc_emoticon_image_path = nil
69
- end
70
-
71
- it "Jpmobile::Emoticon.pc_emoticon? がtrueになること" do
72
- Jpmobile::Emoticon.pc_emoticon?.should be_true
73
- end
74
-
75
- it "docomo 絵文字が画像に変換されること" do
76
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_cr))).call(@res)[2]
77
- response_body(response).should == "<img src=\"#{@path}/sun.gif\" alt=\"sun\" />"
78
- end
79
-
80
- it "docomo 絵文字コードが画像に変換されること" do
81
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@docomo_utf8))).call(@res)[2]
82
- response_body(response).should == "<img src=\"#{@path}/sun.gif\" alt=\"sun\" />"
83
- end
84
-
85
- it "au 絵文字が画像に変換されること" do
86
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_cr))).call(@res)[2]
87
- response_body(response).should == "<img src=\"#{@path}/sun.gif\" alt=\"sun\" />"
88
- end
89
-
90
- it "au 絵文字コードが画像に変換されること" do
91
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@au_utf8))).call(@res)[2]
92
- response_body(response).should == "<img src=\"#{@path}/sun.gif\" alt=\"sun\" />"
93
- end
94
-
95
- it "softbank 絵文字が画像に変換されること" do
96
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_cr))).call(@res)[2]
97
- response_body(response).should == "<img src=\"#{@path}/sun.gif\" alt=\"sun\" />"
98
- end
99
-
100
- it "softbank 絵文字コードが画像に変換されること" do
101
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2]
102
- response_body(response).should == "<img src=\"#{@path}/sun.gif\" alt=\"sun\" />"
103
- end
104
- end
105
-
106
48
  context "docomo のとき" do
107
49
  before(:each) do
108
50
  @res = Rack::MockRequest.env_for(
@@ -273,169 +215,4 @@ describe "絵文字が" do
273
215
  response_body(res).should == [0xe04a].pack('U')
274
216
  end
275
217
  end
276
-
277
- context 'for iPhone' do
278
- context 'lower iOS 4' do
279
- before(:each) do
280
- @res = Rack::MockRequest.env_for(
281
- "/",
282
- 'HTTP_USER_AGENT' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7",
283
- 'Content-Type' => 'text/html; charset=utf-8')
284
- end
285
-
286
- it 'should convert Softbank emoticon' do
287
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_cr))).call(@res)[2]
288
- response_body(response).should == [0xe04a].pack('U')
289
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2]
290
- response_body(response).should == [0xe04a].pack('U')
291
- end
292
-
293
- it "converts query parameters" do
294
- query_string = "q=" + URI.encode([0xe04A].pack("U"))
295
-
296
- res = Rack::MockRequest.env_for(
297
- "/?#{query_string}",
298
- "REQUEST_METHOD" => "GET",
299
- 'HTTP_USER_AGENT' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7",
300
- 'Content-Type' => 'text/html; charset=utf-8')
301
- res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
302
- req = Rack::Request.new(res[1])
303
- req.params['q'].should == [0xf04a].pack("U")
304
- response_body(res).should == [0xe04a].pack('U')
305
- end
306
-
307
- it 'should not convert 〓' do
308
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2]
309
- response_body(response).should == '〓'
310
- end
311
- end
312
-
313
- context 'upper iOS 5' do
314
- before(:each) do
315
- @res = Rack::MockRequest.env_for(
316
- "/",
317
- 'HTTP_USER_AGENT' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A334 Safari/7534.48.3",
318
- 'Content-Type' => 'text/html; charset=utf-8')
319
- @unicode_single = "\342\230\200"
320
- @unicode_multi = "\342\233\205"
321
- end
322
-
323
- it "should convert Unicode emoticon" do
324
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@unicode_single))).call(@res)[2]
325
- response_body(response).should == [0x2600].pack('U*')
326
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@unicode_multi))).call(@res)[2]
327
- response_body(response).should == [0x26C5].pack('U*')
328
- end
329
-
330
- it "converts query parameters" do
331
- query_string = "q=" + URI.encode(@unicode_multi)
332
-
333
- res = Rack::MockRequest.env_for(
334
- "/?#{query_string}",
335
- "REQUEST_METHOD" => "GET",
336
- 'HTTP_USER_AGENT' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7",
337
- 'Content-Type' => 'text/html; charset=utf-8')
338
- res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
339
- req = Rack::Request.new(res[1])
340
- req.params['q'].should == [0x26C5].pack("U")
341
- response_body(res).should == [0x26C5].pack('U')
342
- end
343
-
344
- it 'should not convert 〓' do
345
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2]
346
- response_body(response).should == '〓'
347
- end
348
- end
349
- end
350
-
351
- context 'for Android' do
352
- before(:each) do
353
- @google_single = "\363\276\200\200"
354
- @google_multi = "\363\276\200\217"
355
- end
356
-
357
- context 'mobile' do
358
- before(:each) do
359
- @res = Rack::MockRequest.env_for(
360
- "/",
361
- 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; SonyEriccsonSO-01B Build/R1EA018) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1',
362
- 'Content-Type' => 'text/html; charset=utf-8')
363
- end
364
-
365
- it "should convert Google emoticon" do
366
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@google_single))).call(@res)[2]
367
- response_body(response).should == [0xFE000].pack('U*')
368
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@google_multi))).call(@res)[2]
369
- response_body(response).should == [0xFE00F].pack('U*')
370
- end
371
-
372
- it "converts query parameters irreversibly" do
373
- query_string = "q=" + URI.encode(@google_multi)
374
-
375
- res = Rack::MockRequest.env_for(
376
- "/?#{query_string}",
377
- "REQUEST_METHOD" => "GET",
378
- 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; SonyEriccsonSO-01B Build/R1EA018) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1',
379
- 'Content-Type' => 'text/html; charset=utf-8')
380
- res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
381
- req = Rack::Request.new(res[1])
382
- req.params['q'].should == [0xe63e, 0xe63f].pack("U*")
383
- response_body(res).should == [0xfe000, 0xfe001].pack("U*")
384
- end
385
-
386
- it 'should not convert 〓' do
387
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2]
388
- response_body(response).should == '〓'
389
- end
390
- end
391
-
392
- context 'tablet' do
393
- before(:each) do
394
- @res = Rack::MockRequest.env_for(
395
- "/",
396
- 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
397
- 'Content-Type' => 'text/html; charset=utf-8')
398
- end
399
-
400
- it "should convert Google emoticon" do
401
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@google_single))).call(@res)[2]
402
- response_body(response).should == [0xFE000].pack('U*')
403
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@google_multi))).call(@res)[2]
404
- response_body(response).should == [0xFE00F].pack('U*')
405
- end
406
-
407
- it "converts query parameters irreversibly" do
408
- query_string = "q=" + URI.encode(@google_multi)
409
-
410
- res = Rack::MockRequest.env_for(
411
- "/?#{query_string}",
412
- "REQUEST_METHOD" => "GET",
413
- 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
414
- 'Content-Type' => 'text/html; charset=utf-8')
415
- res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
416
- req = Rack::Request.new(res[1])
417
- req.params['q'].should == [0xe63e, 0xe63f].pack("U*")
418
- response_body(res).should == [0xfe000, 0xfe001].pack("U*")
419
- end
420
-
421
- it 'should not convert 〓' do
422
- response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2]
423
- response_body(response).should == '〓'
424
- end
425
-
426
- it 'should convert unsupported emoticon to "〓"' do
427
- query_string = "q=" + URI.encode("\xF3\xBE\x93\xA4")
428
-
429
- res = Rack::MockRequest.env_for(
430
- "/?#{query_string}",
431
- "REQUEST_METHOD" => "GET",
432
- 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
433
- 'Content-Type' => 'text/html; charset=utf-8')
434
- res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res)
435
- req = Rack::Request.new(res[1])
436
- req.params['q'].should == '〓'
437
- response_body(res).should == '〓'
438
- end
439
- end
440
- end
441
218
  end
@@ -19,12 +19,8 @@ describe Jpmobile::Rack::MobileCarrier do
19
19
  [ Jpmobile::Mobile::Iphone , 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; ja-jp) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16' ],
20
20
  [ Jpmobile::Mobile::Android , 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; SonyEriccsonSO-01B Build/R1EA018) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1' ],
21
21
  [ Jpmobile::Mobile::WindowsPhone , 'Mozilla/4.0 (Compatible; MSIE 6.0; Windows NT 5.1 T-01A_6.5; Windows Phone 6.5)' ],
22
- [ Jpmobile::Mobile::BlackBerry, 'BlackBerry9000/4.6.0.224 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/220' ],
23
- [ Jpmobile::Mobile::Ipad , 'Mozilla/5.0 (iPad; U; CPU OS 4_3 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F191 Safari/6533.18.5'],
24
- [ Jpmobile::Mobile::AndroidTablet, 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'],
25
- [ Jpmobile::Mobile::AndroidTablet, 'Mozilla/5.0 (Linux; U; Android 3.2; ja-jp; Sony Tablet S Build/THMAS11002) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'],
26
22
  ].each do |carrier, user_agent|
27
- it "#mobile should return #{carrier} when take #{user_agent} as UserAgent" do
23
+ it '#mobile should return #{carrier} when take #{user_agent} as UserAgent' do
28
24
  res = Rack::MockRequest.env_for(
29
25
  'http://jpmobile-rails.org/',
30
26
  'HTTP_USER_AGENT' => user_agent)
@@ -70,7 +70,7 @@ describe Jpmobile::Rack::MobileCarrier, "softbank" do
70
70
  res = Rack::MockRequest.env_for(
71
71
  'http://jpmobile-rails.org/',
72
72
  'HTTP_USER_AGENT' => "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
73
- "REMOTE_ADDR"=>"210.146.7.199")
73
+ "REMOTE_ADDR"=>"210.175.1.130")
74
74
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
75
75
 
76
76
  env['rack.jpmobile'].valid_ip?.should be_true
@@ -30,38 +30,6 @@ describe Jpmobile::Emoticon do
30
30
  Jpmobile::Emoticon::unicodecr_to_external("&#xE48E;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK, true).should == [0xe04a, 0xe049].pack('U*')
31
31
  end
32
32
  end
33
-
34
- it 'should convert docomo unicodecr to Unicode 6.0 emoticon' do
35
- Jpmobile::Emoticon.unicodecr_to_external("&#xe63e;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_UNICODE_EMOTICON, false).should == [0x2600].pack('U')
36
- end
37
-
38
- it 'should convert au unicodecr to Unicode 6.0 emoticon' do
39
- Jpmobile::Emoticon.unicodecr_to_external("&#xe48e;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_UNICODE_EMOTICON, false).should == [0x26C5].pack('U')
40
- end
41
-
42
- it 'should convert Softbank unicodecr to Unicode 6.0 emoticon' do
43
- Jpmobile::Emoticon.unicodecr_to_external("&#xf001;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_UNICODE_EMOTICON, false).should == [0x1F466].pack('U')
44
- end
45
-
46
- it 'should not convert 〓' do
47
- Jpmobile::Emoticon.unicodecr_to_external("&#x3013;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_UNICODE_EMOTICON, false).should == '〓'
48
- end
49
-
50
- it 'should convert docomo unicodecr to Google emoticon' do
51
- Jpmobile::Emoticon.unicodecr_to_external("&#xe63e;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_GOOGLE_EMOTICON, false).should == [0xFE000].pack('U')
52
- end
53
-
54
- it 'should convert au unicodecr to Google emoticon' do
55
- Jpmobile::Emoticon.unicodecr_to_external("&#xe48e;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_GOOGLE_EMOTICON, false).should == [0xFE00F].pack('U')
56
- end
57
-
58
- it 'should convert Softbank unicodecr to Google emoticon' do
59
- Jpmobile::Emoticon.unicodecr_to_external("&#xf001;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_GOOGLE_EMOTICON, false).should == [0xFE19B].pack('U')
60
- end
61
-
62
- it 'should not convert 〓' do
63
- Jpmobile::Emoticon.unicodecr_to_external("&#x3013;", Jpmobile::Emoticon::CONVERSION_TABLE_TO_GOOGLE_EMOTICON, false).should == '〓'
64
- end
65
33
  end
66
34
 
67
35
  describe "unicodecr_to_utf8" do
@@ -102,34 +70,6 @@ describe Jpmobile::Emoticon do
102
70
  it "should not convert docomo encoding of koukai-sjis emoticons to unicodecr" do
103
71
  Jpmobile::Emoticon::external_to_unicodecr_docomo(sjis("\x8c\xf6\x8a\x4a")).should == sjis("\x8c\xf6\x8a\x4a")
104
72
  end
105
-
106
- context 'at iPhone emoticon' do
107
- it 'should convert iPhone Unicode emoticon to SoftBank emoticon' do
108
- Jpmobile::Emoticon::external_to_unicodecr_unicode60("\342\230\200").should == "&#xf04a;"
109
- end
110
-
111
- it 'should convert iPhone Unicode emoticon to multi SoftBank emoticons' do
112
- Jpmobile::Emoticon::external_to_unicodecr_unicode60("\342\233\205").should == "&#xF04A;,&#xF049;"
113
- end
114
-
115
- it 'should not convert 〓' do
116
- Jpmobile::Emoticon::external_to_unicodecr_unicode60('〓').should == "〓"
117
- end
118
- end
119
-
120
- context 'at Android emoticon' do
121
- it 'should convert Android Google Unicode emoticon to Docomo emoticon' do
122
- Jpmobile::Emoticon::external_to_unicodecr_google("\363\276\200\200").should == "&#xe63e;"
123
- end
124
-
125
- it 'should convert Android Google Unicode emoticon to multi Docomo emoticon' do
126
- Jpmobile::Emoticon::external_to_unicodecr_google("\363\276\200\217").should == "&#xE63E;&#xE63F;"
127
- end
128
-
129
- it 'should not convert 〓' do
130
- Jpmobile::Emoticon::external_to_unicodecr_google('〓').should == "〓"
131
- end
132
- end
133
73
  end
134
74
 
135
75
  context "for email" do
@@ -145,10 +85,6 @@ describe Jpmobile::Emoticon do
145
85
  it "should not convert ascii string to unicodecr" do
146
86
  Jpmobile::Emoticon.external_to_unicodecr_au_mail(utf8_to_jis("-------=_NextPart_15793_72254_63179")).should_not match(/e5c2/i)
147
87
  end
148
-
149
- it "should not include extra JIS escape sequence between Kanji-code and emoticon" do
150
- Jpmobile::Emoticon.unicodecr_to_au_email(utf8_to_jis("&#xe481;掲示板")).should == Jpmobile::Util.ascii_8bit("\x1b\x24\x42\x75\x3a\x37\x47\x3C\x28\x48\x44\x1b\x28\x42")
151
- end
152
88
  end
153
89
  end
154
90
  end