jpmobile 4.2.5 → 5.0.0.beta1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/jpmobile.gemspec +1 -2
- data/lib/jpmobile.rb +17 -7
- data/lib/jpmobile/configuration.rb +1 -1
- data/lib/jpmobile/encoding.rb +13 -19
- data/lib/jpmobile/{hook_action_controller.rb → fallback_view_selector.rb} +4 -6
- data/lib/jpmobile/filter.rb +13 -10
- data/lib/jpmobile/mobile/abstract_mobile.rb +2 -2
- data/lib/jpmobile/mobile/google_emoticon.rb +2 -2
- data/lib/jpmobile/mobile/smart_phone.rb +2 -2
- data/lib/jpmobile/mobile/unicode_emoticon.rb +2 -2
- data/lib/jpmobile/rack/filter.rb +36 -38
- data/lib/jpmobile/rack/mobile_carrier.rb +8 -10
- data/lib/jpmobile/rack/params_filter.rb +32 -34
- data/lib/jpmobile/rails.rb +17 -4
- data/lib/jpmobile/resolver.rb +2 -3
- data/lib/jpmobile/trans_sid.rb +58 -78
- data/lib/jpmobile/util.rb +0 -17
- data/lib/jpmobile/version.rb +1 -1
- data/lib/tasks/jpmobile_tasks.rake +31 -37
- data/spec/rack/jpmobile/android_spec.rb +2 -2
- data/spec/rack/jpmobile/au_spec.rb +17 -17
- data/spec/rack/jpmobile/black_berry_spec.rb +2 -2
- data/spec/rack/jpmobile/docomo_spec.rb +15 -15
- data/spec/rack/jpmobile/emoticon_spec.rb +57 -57
- data/spec/rack/jpmobile/filter_spec.rb +25 -25
- data/spec/rack/jpmobile/iphone_spec.rb +3 -3
- data/spec/rack/jpmobile/mobile_by_ua_spec.rb +3 -3
- data/spec/rack/jpmobile/params_filter_spec.rb +10 -10
- data/spec/rack/jpmobile/softbank_spec.rb +9 -9
- data/spec/rack/jpmobile/willcom_spec.rb +6 -6
- data/spec/rack/jpmobile/windows_phone.rb +2 -2
- data/spec/rack_helper.rb +0 -1
- data/spec/unit/mail_spec.rb +1 -10
- data/spec/unit/util_spec.rb +42 -56
- data/test/rails/overrides/Gemfile.jpmobile +5 -3
- data/test/rails/overrides/app/controllers/filter_controller.rb +0 -1
- data/test/rails/overrides/app/controllers/filter_controller_base.rb +14 -9
- data/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb +2 -2
- data/test/rails/overrides/app/controllers/trans_sid_metal_controller.rb +0 -1
- data/test/rails/overrides/app/views/filter/text_template.html.erb +1 -0
- data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +3 -3
- data/test/rails/overrides/spec/controllers/trans_sid_controller_spec.rb +2 -2
- data/test/rails/overrides/spec/features/filter_spec.rb +10 -9
- data/test/rails/overrides/spec/helpers/helpers_spec.rb +5 -3
- data/test/rails/overrides/spec/requests/docomo_spec.rb +6 -6
- data/test/rails/overrides/spec/requests/emobile_spec.rb +6 -6
- data/test/rails/overrides/spec/requests/pc_spec.rb +3 -3
- data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +4 -4
- data/test/rails/overrides/spec/requests/template_path_spec.rb +1 -1
- data/test/rails/overrides/spec/requests/trans_sid_spec.rb +7 -9
- metadata +12 -28
- data/lib/jpmobile/hook_action_dispatch.rb +0 -2
- data/lib/jpmobile/rack.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbcc78220f8ee88ca102524a012cb278a111af2b
|
4
|
+
data.tar.gz: 7578e413d0afb4020c51127f6b6e15a5c7c57c4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d8730c91d837df4c844138703365232a8d339e4b0cd0c0438d3812f44644fe2c9be4ee9478294e8aad2afa72195acd5458c18d0a774b0307e50138d0f94fc1d
|
7
|
+
data.tar.gz: 3c72edb2d3fbe357cfcdeb6a6d6a6e4a769be0bae1ba9883e4f20841da5a00f7de2497c9a2d105c2336ecd2ec52a0297c1255c449cea972398e051971680713b
|
data/.gitignore
CHANGED
data/jpmobile.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.require_paths = ["lib"]
|
18
18
|
|
19
|
-
gem.add_development_dependency 'rails', '
|
19
|
+
gem.add_development_dependency 'rails', '5.0.0.beta1'
|
20
20
|
gem.add_development_dependency 'rspec'
|
21
21
|
gem.add_development_dependency 'rspec-rails'
|
22
22
|
gem.add_development_dependency 'rspec-its'
|
@@ -26,5 +26,4 @@ Gem::Specification.new do |gem|
|
|
26
26
|
gem.add_development_dependency 'hpricot'
|
27
27
|
gem.add_development_dependency 'git'
|
28
28
|
gem.add_development_dependency 'pry'
|
29
|
-
gem.add_development_dependency 'mail', '2.5.5'
|
30
29
|
end
|
data/lib/jpmobile.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
|
3
3
|
$:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
4
|
require "jpmobile/version"
|
5
|
+
require 'singleton'
|
6
|
+
require 'rack/utils'
|
5
7
|
|
6
8
|
module Jpmobile
|
7
9
|
autoload :Email, 'jpmobile/email'
|
@@ -52,22 +54,30 @@ module Jpmobile
|
|
52
54
|
require 'jpmobile/mobile/abstract_mobile'
|
53
55
|
end
|
54
56
|
|
55
|
-
# autoload Rack middlewares
|
56
|
-
autoload :Rack, 'jpmobile/rack'
|
57
|
-
module Rack
|
58
|
-
autoload :MobileCarrier, 'jpmobile/rack/mobile_carrier'
|
59
|
-
autoload :ParamsFilter, 'jpmobile/rack/params_filter'
|
60
|
-
autoload :Filter, 'jpmobile/rack/filter'
|
61
|
-
end
|
62
57
|
autoload :Configuration, 'jpmobile/configuration'
|
63
58
|
|
59
|
+
autoload :MobileCarrier, 'jpmobile/rack/mobile_carrier'
|
60
|
+
autoload :ParamsFilter, 'jpmobile/rack/params_filter'
|
61
|
+
autoload :Filter, 'jpmobile/rack/filter'
|
62
|
+
|
64
63
|
autoload :Mailer, 'jpmobile/mailer'
|
65
64
|
autoload :Resolver, 'jpmobile/resolver'
|
66
65
|
|
66
|
+
autoload :FallbackViewSelector, 'jpmobile/fallback_view_selector'
|
67
|
+
|
68
|
+
autoload :TransSidRedirecting, 'jpmobile/trans_sid'
|
69
|
+
autoload :TransSid, 'jpmobile/trans_sid'
|
70
|
+
|
67
71
|
module_function
|
68
72
|
def config
|
69
73
|
::Jpmobile::Configuration.instance
|
70
74
|
end
|
75
|
+
|
76
|
+
def mount_middlewares
|
77
|
+
# 漢字コード・絵文字フィルター
|
78
|
+
::Rails.application.middleware.insert_after ::Jpmobile::MobileCarrier, ::Jpmobile::ParamsFilter
|
79
|
+
::Rails.application.middleware.insert_after ::Jpmobile::ParamsFilter, ::Jpmobile::Filter
|
80
|
+
end
|
71
81
|
end
|
72
82
|
|
73
83
|
if defined?(Rails)
|
data/lib/jpmobile/encoding.rb
CHANGED
@@ -2,28 +2,22 @@
|
|
2
2
|
# params を UTF-8 にする拡張
|
3
3
|
module Jpmobile
|
4
4
|
module Encoding
|
5
|
-
def
|
6
|
-
|
7
|
-
alias_method :parameters_without_jpmobile, :parameters
|
5
|
+
def parameters
|
6
|
+
return @parameters if @jpmobile_params_converted
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@parameters = Jpmobile::Util.deep_convert(@parameters) do |value|
|
16
|
-
value = Jpmobile::Util.utf8(value)
|
17
|
-
end
|
18
|
-
|
19
|
-
@jpmobile_params_converted = true
|
20
|
-
if @parameters.respond_to?(:with_indifferent_access)
|
21
|
-
@parameters = @parameters.with_indifferent_access
|
22
|
-
end
|
8
|
+
# load params
|
9
|
+
@parameters = super
|
10
|
+
# 変換
|
11
|
+
@parameters = Jpmobile::Util.deep_convert(@parameters) do |value|
|
12
|
+
value = Jpmobile::Util.utf8(value)
|
13
|
+
end
|
23
14
|
|
24
|
-
|
25
|
-
|
15
|
+
@jpmobile_params_converted = true
|
16
|
+
if @parameters.respond_to?(:with_indifferent_access)
|
17
|
+
@parameters = @parameters.with_indifferent_access
|
26
18
|
end
|
19
|
+
|
20
|
+
@parameters
|
27
21
|
end
|
28
22
|
end
|
29
23
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'jpmobile/lookup_context'
|
3
3
|
|
4
|
-
module
|
5
|
-
module
|
6
|
-
def
|
4
|
+
module Jpmobile
|
5
|
+
module FallbackViewSelector
|
6
|
+
def render_to_body(options)
|
7
7
|
if Jpmobile.config.fallback_view_selector and
|
8
8
|
lookup_context.mobile.present? and !lookup_context.mobile.empty?
|
9
9
|
begin
|
@@ -21,9 +21,7 @@ module ActionController
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
super(options)
|
25
25
|
end
|
26
|
-
|
27
|
-
alias_method_chain :render_to_body, :jpmobile
|
28
26
|
end
|
29
27
|
end
|
data/lib/jpmobile/filter.rb
CHANGED
@@ -7,12 +7,6 @@ ActiveSupport.on_load(:action_controller) do
|
|
7
7
|
before_action Jpmobile::HankakuFilter.new(options)
|
8
8
|
after_action Jpmobile::HankakuFilter.new(options)
|
9
9
|
end
|
10
|
-
|
11
|
-
def self.mobile_filter(options={})
|
12
|
-
STDERR.puts "Method mobile_filter is now deprecated. Use hankaku_filter instead for Hankaku-conversion."
|
13
|
-
|
14
|
-
self.hankaku_filter(options)
|
15
|
-
end
|
16
10
|
end
|
17
11
|
|
18
12
|
module Jpmobile
|
@@ -75,10 +69,9 @@ module Jpmobile
|
|
75
69
|
|
76
70
|
def before(controller)
|
77
71
|
@controller = controller
|
72
|
+
|
78
73
|
if apply_incoming?
|
79
|
-
|
80
|
-
value = to_internal(value)
|
81
|
-
end
|
74
|
+
@controller.params = convert_parameters(@controller.params.dup)
|
82
75
|
end
|
83
76
|
end
|
84
77
|
|
@@ -128,7 +121,7 @@ module Jpmobile
|
|
128
121
|
end
|
129
122
|
|
130
123
|
def filter(method, str)
|
131
|
-
str = str.
|
124
|
+
str = str.clone
|
132
125
|
|
133
126
|
# 一度UTF-8に変換
|
134
127
|
before_encoding = nil
|
@@ -172,5 +165,15 @@ module Jpmobile
|
|
172
165
|
@controller.request.mobile.default_charset
|
173
166
|
end
|
174
167
|
end
|
168
|
+
|
169
|
+
def convert_parameters(params)
|
170
|
+
params.each do |k, v|
|
171
|
+
if params[k].respond_to?(:each)
|
172
|
+
params[k] = convert_parameters(params[k])
|
173
|
+
else
|
174
|
+
params[k] = to_internal(v)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
175
178
|
end
|
176
179
|
end
|
@@ -58,12 +58,12 @@ module Jpmobile::Mobile
|
|
58
58
|
false
|
59
59
|
end
|
60
60
|
|
61
|
-
# Jpmobile::
|
61
|
+
# Jpmobile::Filter を適用するかどうか
|
62
62
|
def apply_filter?
|
63
63
|
true
|
64
64
|
end
|
65
65
|
|
66
|
-
# Jpmobile::
|
66
|
+
# Jpmobile::ParamsFilter を適用するかどうか
|
67
67
|
def apply_params_filter?
|
68
68
|
true
|
69
69
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
module Jpmobile::Mobile
|
3
3
|
module GoogleEmoticon
|
4
|
-
# Jpmobile::
|
4
|
+
# Jpmobile::Filter を適用する
|
5
5
|
def apply_filter?
|
6
6
|
Jpmobile.config.smart_phone_emoticon_compatibility
|
7
7
|
end
|
8
8
|
|
9
|
-
# Jpmobile::
|
9
|
+
# Jpmobile::ParamsFilter を適用する
|
10
10
|
def apply_params_filter?
|
11
11
|
Jpmobile.config.smart_phone_emoticon_compatibility
|
12
12
|
end
|
@@ -18,12 +18,12 @@ module Jpmobile::Mobile
|
|
18
18
|
true
|
19
19
|
end
|
20
20
|
|
21
|
-
# Jpmobile::
|
21
|
+
# Jpmobile::Filter は適用しない
|
22
22
|
def apply_filter?
|
23
23
|
false
|
24
24
|
end
|
25
25
|
|
26
|
-
# Jpmobile::
|
26
|
+
# Jpmobile::ParamsFilter は適用しない
|
27
27
|
def apply_params_filter?
|
28
28
|
false
|
29
29
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
module Jpmobile::Mobile
|
3
3
|
module UnicodeEmoticon
|
4
|
-
# Jpmobile::
|
4
|
+
# Jpmobile::Filter を適用する
|
5
5
|
def apply_filter?
|
6
6
|
Jpmobile.config.smart_phone_emoticon_compatibility
|
7
7
|
end
|
8
8
|
|
9
|
-
# Jpmobile::
|
9
|
+
# Jpmobile::ParamsFilter を適用する
|
10
10
|
def apply_params_filter?
|
11
11
|
Jpmobile.config.smart_phone_emoticon_compatibility
|
12
12
|
end
|
data/lib/jpmobile/rack/filter.rb
CHANGED
@@ -3,55 +3,53 @@
|
|
3
3
|
require 'scanf'
|
4
4
|
|
5
5
|
module Jpmobile
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(env)
|
13
|
-
# 入力を保存
|
14
|
-
mobile = env['rack.jpmobile']
|
6
|
+
class Filter
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
9
|
+
end
|
15
10
|
|
16
|
-
|
11
|
+
def call(env)
|
12
|
+
# 入力を保存
|
13
|
+
mobile = env['rack.jpmobile']
|
17
14
|
|
18
|
-
|
19
|
-
if mobile and mobile.apply_filter?
|
20
|
-
type, charset = env['Content-Type'].split(/;\s*charset=/)
|
15
|
+
status, env, response = @app.call(env)
|
21
16
|
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
if env['Content-Type'] =~ %r!text/html|application/xhtml\+xml!
|
18
|
+
if mobile and mobile.apply_filter?
|
19
|
+
type, charset = env['Content-Type'].split(/;\s*charset=/)
|
25
20
|
|
26
|
-
|
21
|
+
body = response_to_body(response)
|
22
|
+
body = body.gsub(/<input name="utf8" type="hidden" value="#{[0x2713].pack("U")}"[^>]*?>/, ' ')
|
23
|
+
body = body.gsub(/<input name="utf8" type="hidden" value="✓"[^>]*?>/, ' ')
|
27
24
|
|
28
|
-
|
29
|
-
env['Content-Type'] = "#{type}; charset=#{charset}"
|
30
|
-
end
|
31
|
-
elsif Jpmobile::Emoticon.pc_emoticon?
|
32
|
-
body = response_to_body(response)
|
25
|
+
response, charset = mobile.to_external(body, type, charset)
|
33
26
|
|
34
|
-
|
27
|
+
if type and charset
|
28
|
+
env['Content-Type'] = "#{type}; charset=#{charset}"
|
35
29
|
end
|
36
|
-
|
30
|
+
elsif Jpmobile::Emoticon.pc_emoticon?
|
31
|
+
body = response_to_body(response)
|
37
32
|
|
38
|
-
|
39
|
-
|
33
|
+
response = Jpmobile::Emoticon.emoticons_to_image(body)
|
34
|
+
end
|
40
35
|
end
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
body
|
37
|
+
new_response = ::Rack::Response.new(response, status, env)
|
38
|
+
new_response.finish
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def response_to_body(response)
|
43
|
+
if response.respond_to?(:to_str)
|
44
|
+
response.to_str
|
45
|
+
elsif response.respond_to?(:each)
|
46
|
+
body = []
|
47
|
+
response.each do |part|
|
48
|
+
body << response_to_body(part)
|
54
49
|
end
|
50
|
+
body.join("\n")
|
51
|
+
else
|
52
|
+
body
|
55
53
|
end
|
56
54
|
end
|
57
55
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
# UserAgent から生成すべき class 名を判定する
|
3
3
|
module Jpmobile
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
class MobileCarrier
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
def call(env)
|
10
|
+
env['rack.jpmobile'] = Jpmobile::Mobile::AbstractMobile.carrier(env)
|
12
11
|
|
13
|
-
|
14
|
-
end
|
12
|
+
@app.call(env)
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
17
|
class Rack::Request
|
20
|
-
include Jpmobile::RequestWithMobile
|
18
|
+
include ::Jpmobile::RequestWithMobile
|
21
19
|
end
|
@@ -1,49 +1,47 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
# リクエストパラメータの変換
|
3
3
|
module Jpmobile
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
4
|
+
class ParamsFilter
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
9
|
+
def call(env)
|
10
|
+
# 入力
|
11
|
+
if @mobile = env['rack.jpmobile'] and @mobile.apply_params_filter?
|
12
|
+
# パラメータをkey, valueに分解
|
13
|
+
# form_params
|
14
|
+
unless env['REQUEST_METHOD'] == 'GET' || env['REQUEST_METHOD'] == 'HEAD'
|
15
|
+
unless env['CONTENT_TYPE'] =~ /application\/json|application\/xml/
|
16
|
+
env['rack.input'] = StringIO.new(parse_query(env['rack.input'].read))
|
19
17
|
end
|
20
|
-
|
21
|
-
# query_params
|
22
|
-
env['QUERY_STRING'] = parse_query(env['QUERY_STRING'], mobile)
|
23
18
|
end
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
[status, env, body]
|
20
|
+
# query_params
|
21
|
+
env['QUERY_STRING'] = parse_query(env['QUERY_STRING'])
|
28
22
|
end
|
29
23
|
|
30
|
-
|
31
|
-
def to_internal(str, mobile)
|
32
|
-
::Rack::Utils.escape(mobile.to_internal(::Rack::Utils.unescape(str)))
|
33
|
-
end
|
34
|
-
def parse_query(str, mobile)
|
35
|
-
return nil unless str
|
24
|
+
status, env, body = @app.call(env)
|
36
25
|
|
37
|
-
|
38
|
-
|
39
|
-
k, v = param_pair.split("=")
|
40
|
-
k = to_internal(k, mobile) if k
|
41
|
-
v = to_internal(v, mobile) if v
|
42
|
-
new_array << "#{k}=#{v}" if k
|
43
|
-
end
|
26
|
+
[status, env, body]
|
27
|
+
end
|
44
28
|
|
45
|
-
|
29
|
+
private
|
30
|
+
def to_internal(str)
|
31
|
+
::Rack::Utils.escape(@mobile.to_internal(::Rack::Utils.unescape(str)))
|
32
|
+
end
|
33
|
+
def parse_query(str)
|
34
|
+
return nil unless str
|
35
|
+
|
36
|
+
new_array = []
|
37
|
+
str.split("&").each do |param_pair|
|
38
|
+
k, v = param_pair.split("=")
|
39
|
+
k = to_internal(k) if k
|
40
|
+
v = to_internal(v) if v
|
41
|
+
new_array << "#{k}=#{v}" if k
|
46
42
|
end
|
43
|
+
|
44
|
+
new_array.join("&")
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|