jpmobile 2.0.11 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/Gemfile +3 -4
  2. data/README.rdoc +5 -12
  3. data/Rakefile +1 -1
  4. data/VERSION.yml +2 -2
  5. data/jpmobile.gemspec +3 -2
  6. data/lib/jpmobile.rb +1 -15
  7. data/lib/jpmobile/emoticon.rb +2 -65
  8. data/lib/jpmobile/emoticon/z_combine.rb +1 -17
  9. data/lib/jpmobile/lookup_context.rb +1 -1
  10. data/lib/jpmobile/mail.rb +29 -59
  11. data/lib/jpmobile/mailer.rb +1 -1
  12. data/lib/jpmobile/mobile/abstract_mobile.rb +36 -60
  13. data/lib/jpmobile/mobile/android.rb +0 -2
  14. data/lib/jpmobile/mobile/iphone.rb +25 -1
  15. data/lib/jpmobile/rack.rb +1 -6
  16. data/lib/jpmobile/rails.rb +2 -2
  17. data/lib/jpmobile/resolver.rb +18 -13
  18. data/lib/jpmobile/trans_sid.rb +9 -8
  19. data/lib/jpmobile/util.rb +1 -54
  20. data/lib/tasks/jpmobile_tasks.rake +4 -4
  21. data/spec/rack/jpmobile/emoticon_spec.rb +0 -167
  22. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +1 -5
  23. data/spec/unit/emoticon_spec.rb +0 -60
  24. data/spec/unit/mail_spec.rb +0 -86
  25. data/spec/unit/receive_mail_spec.rb +0 -46
  26. data/spec/unit/util_spec.rb +0 -43
  27. data/test/rails/overrides/Gemfile +4 -19
  28. data/test/rails/overrides/app/controllers/template_path_controller.rb +0 -12
  29. data/test/rails/overrides/spec/mailers/mobile_mailer_spec.rb +0 -10
  30. data/test/rails/overrides/spec/requests/template_path_spec.rb +0 -72
  31. metadata +43 -166
  32. data/lib/jpmobile/emoticon/google.rb +0 -2421
  33. data/lib/jpmobile/emoticon/unicode.rb +0 -2253
  34. data/lib/jpmobile/mobile/android_tablet.rb +0 -12
  35. data/lib/jpmobile/mobile/black_berry.rb +0 -10
  36. data/lib/jpmobile/mobile/google_emoticon.rb +0 -29
  37. data/lib/jpmobile/mobile/ipad.rb +0 -12
  38. data/lib/jpmobile/mobile/tablet.rb +0 -16
  39. data/lib/jpmobile/mobile/unicode_emoticon.rb +0 -43
  40. data/spec/rack/jpmobile/black_berry_spec.rb +0 -20
  41. data/spec/unit/email-fixtures/bounce_with_utf8_part.eml +0 -42
  42. data/spec/unit/email-fixtures/iphone-mail3.eml +0 -56
  43. data/spec/unit/email-fixtures/iphone-message.eml +0 -27
  44. data/spec/unit/mobile/iphone_spec.rb +0 -34
  45. data/spec/unit/variants_spec.rb +0 -128
  46. data/test/rails/overrides/app/views/template_path/smart_phone_only.html.erb +0 -1
  47. data/test/rails/overrides/app/views/template_path/smart_phone_only_smart_phone.html.erb +0 -1
  48. data/test/rails/overrides/app/views/template_path/with_ipd.html.erb +0 -1
  49. data/test/rails/overrides/app/views/template_path/with_ipd_tablet_ipad.html.erb +0 -1
  50. data/test/rails/overrides/app/views/template_path/with_tblt.html.erb +0 -1
  51. data/test/rails/overrides/app/views/template_path/with_tblt_tablet.html.erb +0 -1
  52. data/test/rails/overrides/spec/fixtures/mobile_mailer/bounced-jp.eml +0 -72
  53. data/tools/e4u_conv.rb +0 -122
@@ -21,7 +21,7 @@ module Jpmobile
21
21
  # for multi to addresses
22
22
  Jpmobile::Mobile::AbstractMobile.new(nil, nil)
23
23
  end
24
- self.lookup_context.mobile = @mobile.mail_variants
24
+ self.lookup_context.mobile = @mobile.variants
25
25
 
26
26
  @mobile.decorated = headers.delete(:decorated)
27
27
 
@@ -29,6 +29,16 @@ module Jpmobile::Mobile
29
29
  # 端末を識別する文字列があれば返す。
30
30
  def ident_device; nil; end
31
31
 
32
+ # 当該キャリアのIPアドレス帯域からのアクセスであれば +true+ を返す。
33
+ # そうでなければ +false+ を返す。
34
+ # IP空間が定義されていない場合は +nil+ を返す。
35
+ def self.valid_ip? remote_addr
36
+ @ip_list ||= ip_address_class
37
+ return false unless @ip_list
38
+
39
+ @ip_list.valid_ip?(remote_addr)
40
+ end
41
+
32
42
  def valid_ip?
33
43
  @__valid_ip ||= self.class.valid_ip? @request.ip
34
44
  end
@@ -50,11 +60,6 @@ module Jpmobile::Mobile
50
60
  false
51
61
  end
52
62
 
53
- # tablet かどうか
54
- def tablet?
55
- false
56
- end
57
-
58
63
  # Jpmobile::Rack::Filter を適用するかどうか
59
64
  def apply_filter?
60
65
  true
@@ -80,12 +85,11 @@ module Jpmobile::Mobile
80
85
  def variants
81
86
  return @_variants if @_variants
82
87
 
83
- @_variants = self.class.ancestors.select {|c| c.to_s =~ /^Jpmobile/ && c.to_s !~ /Emoticon/}.map do |klass|
88
+ @_variants = self.class.ancestors.select {|c| c.to_s =~ /^Jpmobile/}.map do |klass|
84
89
  klass = klass.to_s.
85
90
  gsub(/Jpmobile::/, '').
86
91
  gsub(/AbstractMobile::/, '').
87
92
  gsub(/Mobile::SmartPhone/, 'smart_phone').
88
- gsub(/Mobile::Tablet/, 'tablet').
89
93
  gsub(/::/, '_').
90
94
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
91
95
  gsub(/([a-z\d])([A-Z])/, '\1_\2').
@@ -93,24 +97,17 @@ module Jpmobile::Mobile
93
97
  klass =~ /abstract/ ? "mobile" : klass
94
98
  end
95
99
 
96
- if @_variants.include?('tablet')
97
- @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile_/, "tablet_")}
98
- elsif @_variants.include?("smart_phone")
99
- @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile_/, "smart_phone_")}
100
+ if @_variants.include?("smart_phone")
101
+ @_variants = @_variants.reject{|v| v == "mobile"}.map{|v| v.gsub(/mobile/, "smart_phone")}
100
102
  end
101
103
 
102
104
  @_variants || []
103
105
  end
104
- def mail_variants
105
- return @_mail_variants if @_mail_variants
106
-
107
- @_mail_variants = variants == ['mobile'] ? [] : variants
108
- end
109
106
 
110
107
  # メール送信用
111
108
  def to_mail_subject(str)
112
109
  Jpmobile::Util.fold_text(Jpmobile::Emoticon.unicodecr_to_utf8(str)).
113
- map{|text| "=?#{mail_charset}?B?" + [to_mail_encoding(text)].pack('m').gsub(/\n/, '') + "?=" }.
110
+ map{|text| "=?#{mail_charset}?B?" + [to_mail_encoding(text)].pack('m').strip + "?=" }.
114
111
  join("\n\s")
115
112
  end
116
113
  def to_mail_body(str)
@@ -118,8 +115,7 @@ module Jpmobile::Mobile
118
115
  end
119
116
  def mail_charset(charset = nil)
120
117
  # (charset.nil? or charset == "") ? self.class::MAIL_CHARSET : charset
121
- # self.class::MAIL_CHARSET
122
- charset.nil? || charset == '' || charset =~ /US-ASCII/i ? self.class::MAIL_CHARSET : charset
118
+ self.class::MAIL_CHARSET
123
119
  end
124
120
  def content_transfer_encoding(headers)
125
121
  transfer_encoding = headers['Content-Transfer-Encoding']
@@ -178,47 +174,10 @@ module Jpmobile::Mobile
178
174
  @decorated
179
175
  end
180
176
 
181
- class << self
182
- # 当該キャリアのIPアドレス帯域からのアクセスであれば +true+ を返す。
183
- # そうでなければ +false+ を返す。
184
- # IP空間が定義されていない場合は +nil+ を返す。
185
- def valid_ip? remote_addr
186
- @ip_list ||= ip_address_class
187
- return false unless @ip_list
188
-
189
- @ip_list.valid_ip?(remote_addr)
190
- end
191
-
192
- # リクエストがこのクラスに属するか調べる
193
- # メソッド名に関して非常に不安
194
- def check_carrier(env)
195
- user_agent_regexp && user_agent_regexp.match(env['HTTP_USER_AGENT'])
196
- end
197
-
198
- def user_agent_regexp
199
- @_user_agent_regexp ||= self::USER_AGENT_REGEXP
200
- end
201
-
202
- def add_user_agent_regexp(regexp)
203
- @_user_agent_regexp = Regexp.union(user_agent_regexp, regexp)
204
- end
205
-
206
- def carrier(env)
207
- ::Jpmobile::Mobile.carriers.each do |const|
208
- c = ::Jpmobile::Mobile.const_get(const)
209
- if c.check_carrier(env)
210
- res = ::Rack::Request.new(env)
211
- return c.new(env, res)
212
- end
213
- end
214
-
215
- nil
216
- end
217
-
218
- #
219
- def ip_address_class
220
- eval("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split(/::/).last}").new rescue nil
221
- end
177
+ # リクエストがこのクラスに属するか調べる
178
+ # メソッド名に関して非常に不安
179
+ def self.check_carrier(env)
180
+ self::USER_AGENT_REGEXP && env['HTTP_USER_AGENT'] =~ self::USER_AGENT_REGEXP
222
181
  end
223
182
 
224
183
  #XXX: lib/jpmobile.rbのautoloadで先に各キャリアの定数を定義しているから動くのです
@@ -231,6 +190,18 @@ module Jpmobile::Mobile
231
190
  end
232
191
  end
233
192
 
193
+ def self.carrier(env)
194
+ ::Jpmobile::Mobile.carriers.each do |const|
195
+ c = ::Jpmobile::Mobile.const_get(const)
196
+ if c.check_carrier(env)
197
+ res = ::Rack::Request.new(env)
198
+ return c.new(env, res)
199
+ end
200
+ end
201
+
202
+ nil
203
+ end
204
+
234
205
  private
235
206
  # リクエストのパラメータ。
236
207
  def params
@@ -240,5 +211,10 @@ module Jpmobile::Mobile
240
211
  @request.params
241
212
  end
242
213
  end
214
+
215
+ #
216
+ def self.ip_address_class
217
+ eval("::Jpmobile::Mobile::IpAddresses::#{self.to_s.split(/::/).last}").new rescue nil
218
+ end
243
219
  end
244
220
  end
@@ -6,7 +6,5 @@ module Jpmobile::Mobile
6
6
  class Android < SmartPhone
7
7
  # 対応するUser-Agentの正規表現
8
8
  USER_AGENT_REGEXP = /Android/
9
-
10
- include Jpmobile::Mobile::GoogleEmoticon
11
9
  end
12
10
  end
@@ -7,6 +7,30 @@ module Jpmobile::Mobile
7
7
  # 対応するUser-Agentの正規表現
8
8
  USER_AGENT_REGEXP = /iPhone/
9
9
 
10
- include Jpmobile::Mobile::UnicodeEmoticon
10
+ # Jpmobile::Rack::Filter を適用する
11
+ def apply_filter?
12
+ true
13
+ end
14
+
15
+ # Jpmobile::Rack::ParamsFilter を適用する
16
+ def apply_params_filter?
17
+ true
18
+ end
19
+
20
+ # 文字コード変換
21
+ def to_internal(str)
22
+ # 絵文字を数値参照に変換
23
+ str = Jpmobile::Emoticon.external_to_unicodecr_softbank(Jpmobile::Util.utf8(str))
24
+ # 数値参照を UTF-8 に変換
25
+ Jpmobile::Emoticon.unicodecr_to_utf8(str)
26
+ end
27
+ def to_external(str, content_type, charset)
28
+ # UTF-8を数値参照に
29
+ str = Jpmobile::Emoticon.utf8_to_unicodecr(str)
30
+ # 数値参照を絵文字コードに変換
31
+ str = Jpmobile::Emoticon.unicodecr_to_external(str, Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK, false)
32
+
33
+ [str, charset]
34
+ end
11
35
  end
12
36
  end
data/lib/jpmobile/rack.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'rack/utils'
3
- require 'singleton'
4
3
 
5
4
  module Jpmobile
6
5
  module Rack
@@ -13,14 +12,10 @@ module Jpmobile
13
12
  end
14
13
 
15
14
  class Configuration
16
- include Singleton
17
-
18
15
  attr_accessor :form_accept_charset_conversion
19
- attr_accessor :smart_phone_emoticon_compatibility
20
16
 
21
17
  def initialize
22
- @form_accept_charset_conversion = false
23
- @smart_phone_emoticon_compatibility = false
18
+ @form_accept_charset_conversion = false
24
19
  end
25
20
 
26
21
  def mobile_filter
@@ -19,7 +19,7 @@ ActiveSupport.on_load(:before_configuration) do
19
19
  class Application
20
20
  class Configuration
21
21
  def jpmobile
22
- @jpmobile ||= ::Jpmobile.config
22
+ @jpmobile ||= ::Jpmobile::Configuration.new
23
23
  end
24
24
  end
25
25
  end
@@ -45,7 +45,7 @@ module Jpmobile
45
45
  end
46
46
 
47
47
  def disable_mobile_view!
48
- self.lookup_context.mobile = nil
48
+ self.lookup_context.mobile = []
49
49
  end
50
50
  end
51
51
  end
@@ -13,26 +13,31 @@ module Jpmobile
13
13
 
14
14
  def query(path, details, formats)
15
15
  query = build_query(path, details)
16
- templates = []
17
- sanitizer = Hash.new { |h,k| h[k] = Dir["#{File.dirname(k)}/*"] }
18
16
 
19
- Dir[query].each do |p|
20
- next if File.directory?(p) || !sanitizer[p].include?(p)
17
+ # deals with case-insensitive file systems.
18
+ sanitizer = Hash.new { |h,dir| h[dir] = Dir["#{dir}/*"] }
21
19
 
22
- handler, format = extract_handler_and_format(p, formats)
23
- contents = File.open(p, "rb") { |io| io.read }
20
+ template_paths = Dir[query].reject { |filename|
21
+ File.directory?(filename) ||
22
+ !sanitizer[File.dirname(filename)].include?(filename)
23
+ }
24
+
25
+ template_paths.map { |template|
26
+ handler, format = extract_handler_and_format(template, formats)
27
+ contents = File.binread template
24
28
 
25
29
  if format
26
- variant = p.match(/.+#{path}(.+)\.#{format.to_sym.to_s}.*$/) ? $1 : ''
30
+ variant = template.match(/.+#{path}(.+)\.#{format.to_sym.to_s}.*$/) ? $1 : ''
31
+ virtual_path = variant.blank? ? nil : path + variant
27
32
  else
28
- variant = ''
33
+ virtual_path = path.virtual
29
34
  end
30
35
 
31
- templates << ActionView::Template.new(contents, File.expand_path(p), handler,
32
- :virtual_path => path.name + variant, :format => format, :updated_at => mtime(p))
33
- end
34
-
35
- templates
36
+ ActionView::Template.new(contents, File.expand_path(template), handler,
37
+ :virtual_path => virtual_path,
38
+ :format => format,
39
+ :updated_at => mtime(template))
40
+ }
36
41
  end
37
42
  end
38
43
  end
@@ -21,18 +21,19 @@ module Jpmobile
21
21
  end
22
22
  end
23
23
 
24
- case Rails.application.config.session_store.to_s
25
- when "ActionDispatch::Session::MemCacheStore"
26
- require 'jpmobile/session/mem_cache_store'
27
- ActionDispatch::Session::MemCacheStore.send :include, ParamsOverCookie
28
- when "ActiveRecord::SessionStore"
29
- require 'jpmobile/session/active_record_store'
30
- ActionDispatch::Session::AbstractStore.send :include, ParamsOverCookie
24
+ ActiveSupport.on_load(:after_initialize) do
25
+ case Rails.application.config.session_store.to_s
26
+ when "ActionDispatch::Session::MemCacheStore"
27
+ require 'jpmobile/session/mem_cache_store'
28
+ ActionDispatch::Session::MemCacheStore.send :include, ParamsOverCookie
29
+ when "ActiveRecord::SessionStore"
30
+ require 'jpmobile/session/active_record_store'
31
+ ActionDispatch::Session::AbstractStore.send :include, ParamsOverCookie
32
+ end
31
33
  end
32
34
  end
33
35
 
34
36
  module SessionID
35
- require 'action_dispatch/middleware/session/abstract_store'
36
37
  module_function
37
38
 
38
39
  extend ActionDispatch::Session::Compatibility
data/lib/jpmobile/util.rb CHANGED
@@ -91,13 +91,6 @@ module Jpmobile
91
91
  str
92
92
  end
93
93
 
94
- def ascii_compatible!(str)
95
- if str.respond_to?(:encoding) and !str.encoding.ascii_compatible?
96
- str.force_encoding(BINARY)
97
- end
98
- str
99
- end
100
-
101
94
  def utf8_to_sjis(utf8_str)
102
95
  # 波ダッシュ対策
103
96
  utf8_str = wavedash_to_fullwidth_tilde(utf8_str)
@@ -194,7 +187,7 @@ module Jpmobile
194
187
  end
195
188
 
196
189
  def jis_string_regexp
197
- Regexp.compile(Regexp.escape(ascii_8bit("\x1b\x24\x42")) + "(.+?)" + Regexp.escape(ascii_8bit("\x1b\x28\x42")))
190
+ Regexp.compile(Regexp.escape(ascii_8bit("\x1b\x24\x42")) + "(.+)" + Regexp.escape(ascii_8bit("\x1b\x28\x42")))
198
191
  end
199
192
 
200
193
  def encode(str, charset)
@@ -386,51 +379,5 @@ module Jpmobile
386
379
  end
387
380
 
388
381
  end
389
-
390
- def invert_table(hash)
391
- result = {}
392
- hash.keys.each do |key|
393
- if result[hash[key]]
394
- if !key.kind_of?(Array) and !result[hash[key]].kind_of?(Array) and result[hash[key]] > key
395
- result[hash[key]] = key
396
- end
397
- else
398
- result[hash[key]] = key
399
- end
400
- end
401
- result
402
- end
403
-
404
- def decode(str, encoding, charset)
405
- _str = case encoding
406
- when /quoted-printable/i
407
- str.unpack('M').first.strip
408
- when /base64/i
409
- str.unpack('m').first.strip
410
- else
411
- str
412
- end
413
-
414
- _extract_charset = Jpmobile::Util.extract_charset(_str)
415
- charset = _extract_charset unless _extract_charset.blank? or _extract_charset == charset
416
- Jpmobile::Util.set_encoding(_str, charset)
417
- end
418
-
419
- def check_charset(str, charset)
420
- if Object.const_defined?(:Encoding)
421
- # use NKF.guess
422
- ::Encoding.compatible?(NKF.guess(str), ::Encoding.find(charset))
423
- else
424
- true
425
- end
426
- end
427
-
428
- def correct_encoding(str)
429
- if str.encoding != ::Encoding::ASCII_8BIT and NKF.guess(str) != str.encoding
430
- str.force_encoding(NKF.guess(str))
431
- end
432
-
433
- str
434
- end
435
382
  end
436
383
  end
@@ -46,7 +46,7 @@ namespace :test do
46
46
  end
47
47
 
48
48
  # setup jpmobile
49
- plugin_path = File.join(rails_root, 'vendor', 'plugins', 'jpmobile')
49
+ plugin_path = File.join(rails_root, 'lib', 'jpmobile')
50
50
  FileUtils.mkdir_p(plugin_path)
51
51
  FileList["*"].exclude("test").exclude("spec").exclude('vendor').each do |file|
52
52
  FileUtils.cp_r(file, plugin_path)
@@ -54,7 +54,7 @@ namespace :test do
54
54
 
55
55
  # setup jpmobile-ipaddresses
56
56
  begin
57
- plugin_path = File.join(rails_root, 'vendor', 'plugins', 'jpmobile-ipaddresses')
57
+ plugin_path = File.join(rails_root, 'lib', 'jpmobile-ipaddresses')
58
58
  FileUtils.mkdir_p(plugin_path)
59
59
  FileList["vendor/jpmobile-ipaddresses/*"].exclude("test").each do |file|
60
60
  FileUtils.cp_r(file, plugin_path)
@@ -65,7 +65,7 @@ namespace :test do
65
65
 
66
66
  # setup jpmobile-terminfo
67
67
  begin
68
- plugin_path = File.join(rails_root, 'vendor', 'plugins', 'jpmobile-terminfo')
68
+ plugin_path = File.join(rails_root, 'lib', 'jpmobile-terminfo')
69
69
  FileUtils.mkdir_p(plugin_path)
70
70
  FileList["vendor/jpmobile-terminfo/*"].exclude("test").each do |file|
71
71
  FileUtils.cp_r(file, plugin_path)
@@ -92,7 +92,7 @@ END
92
92
 
93
93
  # run tests in rails
94
94
  cd rails_root
95
- # ruby "-S bundle install"
95
+ ruby "-S bundle install"
96
96
  ruby "-S rake db:migrate test" unless skip
97
97
  ruby "-S rake spec"
98
98
  # ruby "-S rspec -b --color spec/requests/filter_spec.rb -e 'jpmobile integration spec HankakuInputFilterController SoftBank 910T からのアクセス it should behave like hankaku_filter :input => true のとき はtextareaの中では半角に変換されないこと'"
@@ -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 = "&#xE63E;";
13
11
  @docomo_utf8 = [0xe63e].pack("U")
14
12
  @docomo_docomopoint = "&#xE6D5;"
@@ -273,169 +271,4 @@ describe "絵文字が" do
273
271
  response_body(res).should == [0xe04a].pack('U')
274
272
  end
275
273
  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
274
  end