jpmobile 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -3
- data/.rubocop.yml +123 -0
- data/CONTRIBUTING.md +16 -14
- data/Gemfile +6 -0
- data/Gemfile.lock +198 -0
- data/README.md +409 -0
- data/Rakefile +9 -9
- data/circle.yml +14 -0
- data/jpmobile.gemspec +9 -10
- data/lib/jpmobile.rb +6 -5
- data/lib/jpmobile/datum_conv.rb +35 -35
- data/lib/jpmobile/docomo_guid.rb +7 -8
- data/lib/jpmobile/email.rb +12 -12
- data/lib/jpmobile/emoticon.rb +85 -76
- data/lib/jpmobile/emoticon/au.rb +1284 -1284
- data/lib/jpmobile/emoticon/conversion_table.rb +3905 -3906
- data/lib/jpmobile/emoticon/docomo.rb +252 -252
- data/lib/jpmobile/emoticon/google.rb +9 -9
- data/lib/jpmobile/emoticon/softbank.rb +471 -471
- data/lib/jpmobile/emoticon/unicode.rb +9 -9
- data/lib/jpmobile/emoticon/z_combine.rb +20 -23
- data/lib/jpmobile/encoding.rb +1 -1
- data/lib/jpmobile/fallback_view_selector.rb +2 -3
- data/lib/jpmobile/filter.rb +44 -47
- data/lib/jpmobile/helpers.rb +38 -38
- data/lib/jpmobile/hook_action_view.rb +7 -7
- data/lib/jpmobile/hook_test_request.rb +0 -1
- data/lib/jpmobile/lookup_context.rb +1 -2
- data/lib/jpmobile/mail.rb +156 -134
- data/lib/jpmobile/mailer.rb +4 -4
- data/lib/jpmobile/mobile/abstract_mobile.rb +62 -36
- data/lib/jpmobile/mobile/android.rb +0 -1
- data/lib/jpmobile/mobile/android_tablet.rb +0 -1
- data/lib/jpmobile/mobile/au.rb +40 -28
- data/lib/jpmobile/mobile/black_berry.rb +0 -1
- data/lib/jpmobile/mobile/ddipocket.rb +1 -2
- data/lib/jpmobile/mobile/docomo.rb +47 -36
- data/lib/jpmobile/mobile/emobile.rb +1 -2
- data/lib/jpmobile/mobile/google_emoticon.rb +1 -1
- data/lib/jpmobile/mobile/ipad.rb +0 -1
- data/lib/jpmobile/mobile/iphone.rb +0 -1
- data/lib/jpmobile/mobile/smart_phone.rb +0 -1
- data/lib/jpmobile/mobile/softbank.rb +24 -20
- data/lib/jpmobile/mobile/tablet.rb +0 -1
- data/lib/jpmobile/mobile/unicode_emoticon.rb +15 -15
- data/lib/jpmobile/mobile/vodafone.rb +0 -1
- data/lib/jpmobile/mobile/willcom.rb +7 -7
- data/lib/jpmobile/mobile/windows_phone.rb +0 -1
- data/lib/jpmobile/path_set.rb +1 -1
- data/lib/jpmobile/position.rb +30 -14
- data/lib/jpmobile/rack/filter.rb +4 -4
- data/lib/jpmobile/rack/mobile_carrier.rb +0 -1
- data/lib/jpmobile/rack/params_filter.rb +7 -6
- data/lib/jpmobile/rails.rb +3 -4
- data/lib/jpmobile/request_with_mobile.rb +9 -6
- data/lib/jpmobile/resolver.rb +23 -17
- data/lib/jpmobile/session/active_record_store.rb +7 -9
- data/lib/jpmobile/session/mem_cache_store.rb +7 -9
- data/lib/jpmobile/sinatra.rb +1 -1
- data/lib/jpmobile/trans_sid.rb +15 -20
- data/lib/jpmobile/util.rb +61 -77
- data/lib/jpmobile/version.rb +1 -1
- data/lib/tasks/jpmobile_tasks.rake +35 -28
- data/spec/rack/jpmobile/android_spec.rb +5 -5
- data/spec/rack/jpmobile/au_spec.rb +74 -59
- data/spec/rack/jpmobile/black_berry_spec.rb +5 -5
- data/spec/rack/jpmobile/docomo_spec.rb +77 -64
- data/spec/rack/jpmobile/emoticon_spec.rb +137 -121
- data/spec/rack/jpmobile/filter_spec.rb +149 -128
- data/spec/rack/jpmobile/iphone_spec.rb +9 -8
- data/spec/rack/jpmobile/mobile_by_ua_spec.rb +22 -21
- data/spec/rack/jpmobile/params_filter_spec.rb +104 -96
- data/spec/rack/jpmobile/softbank_spec.rb +49 -42
- data/spec/rack/jpmobile/willcom_spec.rb +22 -18
- data/spec/rack/jpmobile/windows_phone.rb +5 -5
- data/spec/rack_helper.rb +9 -8
- data/spec/spec_helper.rb +5 -6
- data/spec/unit/decorated_mail_spec.rb +8 -9
- data/spec/unit/email_spec.rb +44 -44
- data/spec/unit/emoticon_spec.rb +57 -58
- data/spec/unit/encoding_spec.rb +35 -36
- data/spec/unit/is_carrier_spec.rb +49 -49
- data/spec/unit/mail_spec.rb +153 -143
- data/spec/unit/mobile/iphone_spec.rb +6 -7
- data/spec/unit/receive_mail_spec.rb +172 -173
- data/spec/unit/spec_helper.rb +6 -6
- data/spec/unit/util_spec.rb +125 -46
- data/spec/unit/valid_ip_spec.rb +35 -35
- data/spec/unit/variants_spec.rb +18 -19
- data/test/rails/overrides/Gemfile +54 -0
- data/test/rails/overrides/Gemfile.jpmobile +1 -2
- data/test/rails/overrides/app/controllers/admin/top_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/filter_controller_base.rb +14 -6
- data/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/template_path_controller.rb +1 -2
- data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -10
- data/test/rails/overrides/app/controllers/trans_sid_metal_controller.rb +0 -1
- data/test/rails/overrides/app/mailers/decorated_mailer.rb +3 -4
- data/test/rails/overrides/app/mailers/mobile_mailer.rb +5 -6
- data/test/rails/overrides/app/mailers/normal_mailer.rb +2 -3
- data/test/rails/overrides/autotest/discover.rb +2 -2
- data/test/rails/overrides/config/initializers/jpmobile_generator.rb +2 -2
- data/test/rails/overrides/config/routes.rb +95 -2
- data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +2 -2
- data/test/rails/overrides/db/migrate/20100824062306_create_users.rb +1 -1
- data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +24 -25
- data/test/rails/overrides/spec/controllers/helpers_spec.rb +88 -88
- data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +9 -9
- data/test/rails/overrides/spec/controllers/template_path_spec.rb +19 -19
- data/test/rails/overrides/spec/features/admin/top_spec.rb +7 -7
- data/test/rails/overrides/spec/features/filter_spec.rb +101 -102
- data/test/rails/overrides/spec/helpers/helpers_spec.rb +4 -4
- data/test/rails/overrides/spec/mailers/decorated_mailer_spec.rb +12 -12
- data/test/rails/overrides/spec/mailers/mobile_mailer_spec.rb +209 -194
- data/test/rails/overrides/spec/mailers/normal_mailer_spec.rb +10 -10
- data/test/rails/overrides/spec/rails_helper.rb +1 -1
- data/test/rails/overrides/spec/requests/docomo_spec.rb +13 -13
- data/test/rails/overrides/spec/requests/emobile_spec.rb +19 -19
- data/test/rails/overrides/spec/requests/pc_spec.rb +6 -6
- data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +6 -6
- data/test/rails/overrides/spec/requests/template_path_spec.rb +60 -60
- data/test/rails/overrides/spec/requests/trans_sid_spec.rb +89 -89
- data/test/sinatra/test/filter_test.rb +10 -11
- data/tools/e4u_conv.rb +0 -1
- metadata +18 -14
- data/README +0 -0
- data/README.rdoc +0 -308
data/lib/jpmobile/rack/filter.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
# 出力変換
|
3
2
|
require 'scanf'
|
4
3
|
|
@@ -14,8 +13,8 @@ module Jpmobile
|
|
14
13
|
|
15
14
|
status, env, response = @app.call(env)
|
16
15
|
|
17
|
-
if env['Content-Type'] =~ %r
|
18
|
-
if mobile
|
16
|
+
if env['Content-Type'] =~ %r{text/html|application/xhtml\+xml}
|
17
|
+
if mobile && mobile.apply_filter?
|
19
18
|
type, charset = env['Content-Type'].split(/;\s*charset=/)
|
20
19
|
|
21
20
|
body = response_to_body(response)
|
@@ -24,7 +23,7 @@ module Jpmobile
|
|
24
23
|
|
25
24
|
response, charset = mobile.to_external(body, type, charset)
|
26
25
|
|
27
|
-
if type
|
26
|
+
if type && charset
|
28
27
|
env['Content-Type'] = "#{type}; charset=#{charset}"
|
29
28
|
end
|
30
29
|
elsif Jpmobile::Emoticon.pc_emoticon?
|
@@ -39,6 +38,7 @@ module Jpmobile
|
|
39
38
|
end
|
40
39
|
|
41
40
|
private
|
41
|
+
|
42
42
|
def response_to_body(response)
|
43
43
|
if response.respond_to?(:to_str)
|
44
44
|
response.to_str
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
# リクエストパラメータの変換
|
3
2
|
module Jpmobile
|
4
3
|
class ParamsFilter
|
@@ -8,11 +7,11 @@ module Jpmobile
|
|
8
7
|
|
9
8
|
def call(env)
|
10
9
|
# 入力
|
11
|
-
if @mobile = env['rack.jpmobile']
|
10
|
+
if (@mobile = env['rack.jpmobile']) && @mobile.apply_params_filter?
|
12
11
|
# パラメータをkey, valueに分解
|
13
12
|
# form_params
|
14
13
|
unless env['REQUEST_METHOD'] == 'GET' || env['REQUEST_METHOD'] == 'HEAD'
|
15
|
-
unless env['CONTENT_TYPE'] =~ /
|
14
|
+
unless env['CONTENT_TYPE'] =~ %r{application/json|application/xml}
|
16
15
|
env['rack.input'] = StringIO.new(parse_query(env['rack.input'].read))
|
17
16
|
end
|
18
17
|
end
|
@@ -27,21 +26,23 @@ module Jpmobile
|
|
27
26
|
end
|
28
27
|
|
29
28
|
private
|
29
|
+
|
30
30
|
def to_internal(str)
|
31
31
|
::Rack::Utils.escape(@mobile.to_internal(::Rack::Utils.unescape(str)))
|
32
32
|
end
|
33
|
+
|
33
34
|
def parse_query(str)
|
34
35
|
return nil unless str
|
35
36
|
|
36
37
|
new_array = []
|
37
|
-
str.split(
|
38
|
-
k, v = param_pair.split(
|
38
|
+
str.split('&').each do |param_pair|
|
39
|
+
k, v = param_pair.split('=')
|
39
40
|
k = to_internal(k) if k
|
40
41
|
v = to_internal(v) if v
|
41
42
|
new_array << "#{k}=#{v}" if k
|
42
43
|
end
|
43
44
|
|
44
|
-
new_array.join(
|
45
|
+
new_array.join('&')
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
data/lib/jpmobile/rails.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
ActiveSupport.on_load(:action_controller) do
|
3
2
|
require 'jpmobile/docomo_guid'
|
4
3
|
require 'jpmobile/filter'
|
@@ -14,10 +13,10 @@ end
|
|
14
13
|
|
15
14
|
ActiveSupport.on_load(:after_initialize) do
|
16
15
|
case Rails.application.config.session_store.to_s
|
17
|
-
when
|
16
|
+
when 'ActionDispatch::Session::MemCacheStore'
|
18
17
|
require 'jpmobile/session/mem_cache_store'
|
19
18
|
ActionDispatch::Session::MemCacheStore.send :prepend, Jpmobile::ParamsOverCookie
|
20
|
-
when
|
19
|
+
when 'ActionDispatch::Session::ActiveRecordStore'
|
21
20
|
require 'jpmobile/session/active_record_store'
|
22
21
|
ActionDispatch::Session::AbstractStore.send :prepend, Jpmobile::ParamsOverCookie
|
23
22
|
else
|
@@ -47,7 +46,7 @@ module Jpmobile
|
|
47
46
|
before_action :register_mobile
|
48
47
|
|
49
48
|
self._view_paths = self._view_paths.dup
|
50
|
-
self.view_paths.unshift(*self.view_paths.map {|resolver| Jpmobile::Resolver.new(resolver.to_path) })
|
49
|
+
self.view_paths.unshift(*self.view_paths.map { |resolver| Jpmobile::Resolver.new(resolver.to_path) })
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
#
|
3
2
|
# jpmobile の各機能を提供するモジュール
|
4
3
|
# envメソッドが実装されている必要がある。
|
@@ -13,22 +12,26 @@ module Jpmobile
|
|
13
12
|
# for reverse proxy.
|
14
13
|
def remote_addr
|
15
14
|
if respond_to?(:remote_ip)
|
16
|
-
|
15
|
+
__send__(:remote_ip) # for Rails
|
17
16
|
elsif respond_to?(:ip)
|
18
|
-
|
17
|
+
__send__(:ip) # for Rack
|
19
18
|
else
|
20
|
-
|
19
|
+
if env['HTTP_X_FORWARDED_FOR']
|
20
|
+
env['HTTP_X_FORWARDED_FOR'].split(',').pop
|
21
|
+
else
|
22
|
+
env['REMOTE_ADDR']
|
23
|
+
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
27
|
# 環境変数 HTTP_USER_AGENT を設定する。
|
25
28
|
def user_agent=(str)
|
26
|
-
self.env[
|
29
|
+
self.env['HTTP_USER_AGENT'] = str
|
27
30
|
end
|
28
31
|
|
29
32
|
# 携帯電話からであれば +true+を、そうでなければ +false+ を返す。
|
30
33
|
def mobile?
|
31
|
-
mobile and
|
34
|
+
mobile and !mobile.smart_phone?
|
32
35
|
end
|
33
36
|
|
34
37
|
# viewの切り替えをするかどうか
|
data/lib/jpmobile/resolver.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Jpmobile
|
2
2
|
class Resolver < ActionView::FileSystemResolver
|
3
|
-
EXTENSIONS = [:locale, :formats, :handlers, :mobile]
|
4
|
-
DEFAULT_PATTERN =
|
3
|
+
EXTENSIONS = [:locale, :formats, :handlers, :mobile].freeze
|
4
|
+
DEFAULT_PATTERN = ':prefix/:action{_:mobile,}{.:locale,}{.:formats,}{+:variants,}{.:handlers,}'.freeze
|
5
5
|
|
6
|
-
def initialize(path, pattern=nil)
|
7
|
-
raise ArgumentError,
|
6
|
+
def initialize(path, pattern = nil)
|
7
|
+
raise ArgumentError, 'path already is a Resolver class' if path.is_a?(Resolver)
|
8
8
|
super(path, pattern || DEFAULT_PATTERN)
|
9
9
|
@path = File.expand_path(path)
|
10
10
|
end
|
@@ -21,7 +21,7 @@ module Jpmobile
|
|
21
21
|
self.class_eval do
|
22
22
|
def find_template_paths(query)
|
23
23
|
# deals with case-insensitive file systems.
|
24
|
-
sanitizer = Hash.new { |h,dir| h[dir] = Dir["#{dir}/*"] }
|
24
|
+
sanitizer = Hash.new { |h, dir| h[dir] = Dir["#{dir}/*"] }
|
25
25
|
|
26
26
|
Dir[query].reject { |filename|
|
27
27
|
File.directory?(filename) ||
|
@@ -37,18 +37,24 @@ module Jpmobile
|
|
37
37
|
handler, format, variant = extract_handler_and_format_and_variant(template, formats)
|
38
38
|
contents = File.binread(template)
|
39
39
|
|
40
|
-
if format
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
40
|
+
virtual_path = if format
|
41
|
+
if template =~ /.+#{path}(.+)\.#{format.to_sym.to_s}.*$/
|
42
|
+
path.to_str + Regexp.last_match(1)
|
43
|
+
else
|
44
|
+
path.virtual
|
45
|
+
end
|
46
|
+
else
|
47
|
+
path.virtual
|
48
|
+
end
|
49
|
+
|
50
|
+
ActionView::Template.new(
|
51
|
+
contents,
|
52
|
+
File.expand_path(template),
|
53
|
+
handler,
|
54
|
+
virtual_path: virtual_path,
|
55
|
+
format: format,
|
56
|
+
variant: variant,
|
57
|
+
updated_at: mtime(template)
|
52
58
|
)
|
53
59
|
}
|
54
60
|
end
|
@@ -1,13 +1,11 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
destroy_session_without_jpmobile(env, session_id, options)
|
1
|
+
module Jpmobile
|
2
|
+
module ActiveRecordStoreRegenerateSessionId
|
3
|
+
def destroy_session(env, session_id, options)
|
4
|
+
super(env, session_id, options)
|
6
5
|
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
alias_method_chain :destroy_session, :jpmobile
|
6
|
+
session_id || Jpmobile::SessionID.generate_sid
|
11
7
|
end
|
12
8
|
end
|
13
9
|
end
|
10
|
+
|
11
|
+
ActionDispatch::Session::ActiveRecordStore.send :prepend, Jpmobile::ActiveRecordStoreRegenerateSessionId
|
@@ -1,13 +1,11 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
destroy_session_without_jpmobile(env, session_id, options)
|
1
|
+
module Jpmobile
|
2
|
+
module MemCacheStoreRegenerateSessionId
|
3
|
+
def destroy_session(env, session_id, options)
|
4
|
+
super(env, session_id, options)
|
6
5
|
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
alias_method_chain :destroy_session, :jpmobile
|
6
|
+
session_id || generate_sid
|
11
7
|
end
|
12
8
|
end
|
13
9
|
end
|
10
|
+
|
11
|
+
ActionDispatch::Session::MemCacheStore.send :prepend, Jpmobile::MemCacheStoreRegenerateSessionId
|
data/lib/jpmobile/sinatra.rb
CHANGED
@@ -4,7 +4,7 @@ module Jpmobile
|
|
4
4
|
# Calls the given block for every possible template file in views,
|
5
5
|
# named name.ext, where ext is registered on engine.
|
6
6
|
def find_template(views, name, engine)
|
7
|
-
if env['rack.jpmobile']
|
7
|
+
if env['rack.jpmobile'] && !env['rack.jpmobile'].variants.empty?
|
8
8
|
env['rack.jpmobile'].variants.each do |variant|
|
9
9
|
yield ::File.join(views, "#{name}_#{variant}.#{@preferred_extension}")
|
10
10
|
end
|
data/lib/jpmobile/trans_sid.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
# = セッションIDの付与
|
3
2
|
require 'active_support/version'
|
4
3
|
|
5
4
|
module Jpmobile
|
6
5
|
module SessionID
|
7
6
|
require 'action_dispatch/middleware/session/abstract_store'
|
7
|
+
|
8
8
|
module_function
|
9
9
|
|
10
10
|
extend ActionDispatch::Session::Compatibility
|
@@ -12,7 +12,7 @@ module Jpmobile
|
|
12
12
|
|
13
13
|
module ParamsOverCookie
|
14
14
|
def extract_session_id(req)
|
15
|
-
if req.params[@key]
|
15
|
+
if req.params[@key] && !@cookie_only
|
16
16
|
sid = req.params[@key]
|
17
17
|
end
|
18
18
|
sid ||= req.cookies[@key]
|
@@ -26,21 +26,21 @@ module Jpmobile
|
|
26
26
|
end
|
27
27
|
|
28
28
|
protected
|
29
|
+
|
29
30
|
# URLにsession_idを追加する。
|
30
31
|
def default_url_options
|
31
32
|
result = super || {}.with_indifferent_access
|
32
33
|
return result unless request # for test process
|
33
34
|
return result unless apply_trans_sid?
|
34
|
-
|
35
|
+
result.merge({ session_key.to_sym => jpmobile_session_id })
|
35
36
|
end
|
36
37
|
|
37
38
|
private
|
39
|
+
|
38
40
|
# session_keyを返す。
|
39
41
|
def session_key
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
key
|
42
|
+
Rails.application.config.session_options.merge(request.session_options || {})[:key] ||
|
43
|
+
ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS[:key]
|
44
44
|
end
|
45
45
|
|
46
46
|
# session_idを返す
|
@@ -52,7 +52,7 @@ module Jpmobile
|
|
52
52
|
|
53
53
|
# session_idを埋め込むためのhidden fieldを出力する。
|
54
54
|
def sid_hidden_field_tag
|
55
|
-
"<input type=\"hidden\" name=\"#{CGI
|
55
|
+
"<input type=\"hidden\" name=\"#{CGI.escapeHTML session_key}\" value=\"#{CGI.escapeHTML jpmobile_session_id}\" />"
|
56
56
|
end
|
57
57
|
|
58
58
|
# formにsession_idを追加する。
|
@@ -60,18 +60,16 @@ module Jpmobile
|
|
60
60
|
return unless request # for test process
|
61
61
|
return unless apply_trans_sid?
|
62
62
|
return unless jpmobile_session_id
|
63
|
-
response.body = response.body.gsub(%r{(</form>)}i, sid_hidden_field_tag+'\1')
|
63
|
+
response.body = response.body.gsub(%r{(</form>)}i, sid_hidden_field_tag + '\1')
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
module TransSidRedirecting
|
68
68
|
def redirect_to(options = {}, response_status = {})
|
69
|
-
if apply_trans_sid?
|
69
|
+
if apply_trans_sid? && jpmobile_session_id && options != :back && options !~ /^\w[\w+.-]*:.*/
|
70
70
|
case options
|
71
|
-
when %r{^\w[\w+.-]*:.*}
|
72
|
-
# nothing to do
|
73
71
|
when String
|
74
|
-
unless options
|
72
|
+
unless options =~ /#{session_key}/
|
75
73
|
url = URI.parse(options)
|
76
74
|
if url.query
|
77
75
|
url.query += "&#{session_key}=#{jpmobile_session_id}"
|
@@ -80,14 +78,10 @@ module Jpmobile
|
|
80
78
|
end
|
81
79
|
options = url.to_s
|
82
80
|
end
|
83
|
-
when :back
|
84
|
-
# nothing to do
|
85
81
|
when Hash
|
86
82
|
unless options[session_key.to_sym]
|
87
83
|
options[session_key.to_sym] = jpmobile_session_id
|
88
84
|
end
|
89
|
-
else
|
90
|
-
# nothing to do
|
91
85
|
end
|
92
86
|
end
|
93
87
|
|
@@ -109,21 +103,22 @@ module ActionController
|
|
109
103
|
end
|
110
104
|
|
111
105
|
private
|
106
|
+
|
112
107
|
# trans_sidを適用すべきかを返す。
|
113
108
|
def apply_trans_sid?
|
114
109
|
# session_id が blank の場合は適用しない
|
115
|
-
return false if trans_sid_mode
|
110
|
+
return false if trans_sid_mode && jpmobile_session_id.blank?
|
116
111
|
|
117
112
|
case trans_sid_mode
|
118
113
|
when :always
|
119
114
|
return true
|
120
115
|
when :mobile
|
121
|
-
if request.mobile?
|
116
|
+
if request.mobile? && !request.mobile.supports_cookie?
|
122
117
|
return true
|
123
118
|
end
|
124
119
|
end
|
125
120
|
|
126
|
-
|
121
|
+
false
|
127
122
|
end
|
128
123
|
end
|
129
124
|
end
|
data/lib/jpmobile/util.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
require 'tempfile'
|
3
|
-
require 'nkf'
|
4
2
|
|
5
3
|
module Jpmobile
|
6
4
|
module Util
|
7
5
|
# SJIS = "Shift_JIS"
|
8
|
-
SJIS =
|
9
|
-
UTF8 =
|
10
|
-
JIS =
|
11
|
-
JIS_WIN =
|
12
|
-
BINARY =
|
6
|
+
SJIS = 'Windows-31J'.freeze
|
7
|
+
UTF8 = 'UTF-8'.freeze
|
8
|
+
JIS = 'ISO-2022-JP'.freeze
|
9
|
+
JIS_WIN = 'CP50220'.freeze
|
10
|
+
BINARY = 'ASCII-8BIT'.freeze
|
13
11
|
|
14
|
-
WAVE_DASH = [0x301c].pack(
|
15
|
-
FULLWIDTH_TILDE = [0xff5e].pack(
|
12
|
+
WAVE_DASH = [0x301c].pack('U')
|
13
|
+
FULLWIDTH_TILDE = [0xff5e].pack('U')
|
16
14
|
|
17
|
-
OVERLINE = [0x203e].pack(
|
18
|
-
FULLWIDTH_MACRON = [0xffe3].pack(
|
15
|
+
OVERLINE = [0x203e].pack('U')
|
16
|
+
FULLWIDTH_MACRON = [0xffe3].pack('U')
|
19
17
|
|
20
|
-
EM_DASH = [0x2014].pack(
|
21
|
-
HORIZONTAL_BAR = [0x2015].pack(
|
18
|
+
EM_DASH = [0x2014].pack('U')
|
19
|
+
HORIZONTAL_BAR = [0x2015].pack('U')
|
22
20
|
|
23
|
-
MINUS_SIGN = [0x2212].pack(
|
24
|
-
FULLWIDTH_HYPHEN_MINUS = [0xFF0D].pack(
|
21
|
+
MINUS_SIGN = [0x2212].pack('U')
|
22
|
+
FULLWIDTH_HYPHEN_MINUS = [0xFF0D].pack('U')
|
25
23
|
|
26
24
|
module_function
|
25
|
+
|
27
26
|
def deep_convert(obj, &proc)
|
28
27
|
case obj
|
29
28
|
when Hash
|
@@ -37,10 +36,10 @@ module Jpmobile
|
|
37
36
|
deep_convert(value, &proc)
|
38
37
|
end
|
39
38
|
when Symbol
|
40
|
-
new_obj =
|
39
|
+
new_obj = yield(obj.to_s).to_sym
|
41
40
|
when String
|
42
41
|
obj = obj.to_param if obj.respond_to?(:to_param)
|
43
|
-
new_obj =
|
42
|
+
new_obj = yield(obj)
|
44
43
|
else
|
45
44
|
# NilClass, TrueClass, FalseClass, Tempfile, StringIO, etc...
|
46
45
|
new_obj = obj
|
@@ -50,43 +49,43 @@ module Jpmobile
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def sjis(str)
|
53
|
-
|
54
|
-
str.force_encoding(SJIS)
|
52
|
+
unless shift_jis?(str)
|
53
|
+
str = str.dup.force_encoding(SJIS)
|
55
54
|
end
|
56
55
|
str
|
57
56
|
end
|
58
57
|
|
59
58
|
def utf8(str)
|
60
|
-
|
61
|
-
str.force_encoding(UTF8)
|
59
|
+
unless utf8?(str)
|
60
|
+
str = str.dup.force_encoding(UTF8)
|
62
61
|
end
|
63
62
|
str
|
64
63
|
end
|
65
64
|
|
66
65
|
def jis(str)
|
67
|
-
|
68
|
-
str.force_encoding(JIS)
|
66
|
+
unless jis?(str)
|
67
|
+
str = str.dup.force_encoding(JIS)
|
69
68
|
end
|
70
69
|
str
|
71
70
|
end
|
72
71
|
|
73
72
|
def jis_win(str)
|
74
|
-
|
75
|
-
str.force_encoding(JIS_WIN)
|
73
|
+
unless jis?(str)
|
74
|
+
str = str.dup.force_encoding(JIS_WIN)
|
76
75
|
end
|
77
76
|
str
|
78
77
|
end
|
79
78
|
|
80
79
|
def ascii_8bit(str)
|
81
|
-
|
82
|
-
str.force_encoding(BINARY)
|
80
|
+
unless ascii_8bit?(str)
|
81
|
+
str = str.dup.force_encoding(BINARY)
|
83
82
|
end
|
84
83
|
str
|
85
84
|
end
|
86
85
|
|
87
86
|
def ascii_compatible!(str)
|
88
|
-
|
89
|
-
str.force_encoding(BINARY)
|
87
|
+
unless str.encoding.ascii_compatible?
|
88
|
+
str = str.dup.force_encoding(BINARY)
|
90
89
|
end
|
91
90
|
str
|
92
91
|
end
|
@@ -101,21 +100,13 @@ module Jpmobile
|
|
101
100
|
# マイナス対策(不可逆的)
|
102
101
|
utf8_str = minus_sign_to_fullwidth_hyphen_minus(utf8_str)
|
103
102
|
|
104
|
-
|
105
|
-
utf8_str.
|
103
|
+
utf8_str.
|
106
104
|
gsub(/(\r\n|\r|\n)/, "\r\n").
|
107
|
-
encode(SJIS, :
|
108
|
-
else
|
109
|
-
NKF.nkf("-m0 -x -W --oc=cp932 --fb-subchar=63", utf8_str).gsub(/(\r\n|\r|\n)/, "\r\n")
|
110
|
-
end
|
105
|
+
encode(SJIS, undef: :replace, replace: '?')
|
111
106
|
end
|
112
107
|
|
113
108
|
def sjis_to_utf8(sjis_str)
|
114
|
-
utf8_str =
|
115
|
-
sjis_str.encode("UTF-8", :universal_newline => true)
|
116
|
-
else
|
117
|
-
NKF.nkf("-m0 -x -w --ic=cp932", sjis_str).gsub(/\r\n?/, "\n")
|
118
|
-
end
|
109
|
+
utf8_str = sjis_str.encode('UTF-8', universal_newline: true)
|
119
110
|
|
120
111
|
# 波ダッシュ対策
|
121
112
|
fullwidth_tilde_to_wavedash(utf8_str)
|
@@ -125,21 +116,13 @@ module Jpmobile
|
|
125
116
|
# 波ダッシュ対策
|
126
117
|
utf8_str = fullwidth_tilde_to_wavedash(utf8_str)
|
127
118
|
|
128
|
-
|
129
|
-
utf8_str.
|
119
|
+
utf8_str.
|
130
120
|
gsub(/(\r\n|\r|\n)/, "\r\n").
|
131
|
-
encode(JIS, :
|
132
|
-
else
|
133
|
-
NKF.nkf("-m0 -x -Wj --fb-subchar=63", utf8_str).gsub(/(\r\n|\r|\n)/, "\r\n")
|
134
|
-
end
|
121
|
+
encode(JIS, undef: :replace, replace: '?')
|
135
122
|
end
|
136
123
|
|
137
124
|
def jis_to_utf8(jis_str)
|
138
|
-
|
139
|
-
jis_str.encode(UTF8, :universal_newline => true)
|
140
|
-
else
|
141
|
-
NKF.nkf("-m0 -x -Jw", jis_str).gsub(/\r\n?/, "\n")
|
142
|
-
end
|
125
|
+
jis_str.encode(UTF8, universal_newline: true)
|
143
126
|
end
|
144
127
|
|
145
128
|
def regexp_utf8_to_sjis(utf8_str)
|
@@ -152,13 +135,13 @@ module Jpmobile
|
|
152
135
|
|
153
136
|
def hash_to_utf8(hash)
|
154
137
|
new_hash = {}
|
155
|
-
hash.each do |
|
138
|
+
hash.each do |key, value|
|
156
139
|
new_hash[utf8(key)] = utf8(value)
|
157
140
|
end
|
158
141
|
end
|
159
142
|
|
160
143
|
def sjis_regexp(sjis)
|
161
|
-
sjis_str = if sjis.
|
144
|
+
sjis_str = if sjis.is_a?(Numeric)
|
162
145
|
[sjis].pack('n')
|
163
146
|
else
|
164
147
|
sjis
|
@@ -168,26 +151,26 @@ module Jpmobile
|
|
168
151
|
end
|
169
152
|
|
170
153
|
def jis_regexp(jis)
|
171
|
-
jis_str = jis.
|
154
|
+
jis_str = jis.is_a?(Numeric) ? [jis].pack('n') : jis
|
172
155
|
|
173
156
|
Regexp.compile(Regexp.escape(jis_str.force_encoding(BINARY)))
|
174
157
|
end
|
175
158
|
|
176
159
|
def jis_string_regexp
|
177
|
-
Regexp.compile(Regexp.escape(ascii_8bit("\x1b\x24\x42")) +
|
160
|
+
Regexp.compile(Regexp.escape(ascii_8bit("\x1b\x24\x42")) + '(.+?)' + Regexp.escape(ascii_8bit("\x1b\x28\x42")))
|
178
161
|
end
|
179
162
|
|
180
163
|
def encode(str, charset)
|
181
|
-
if
|
182
|
-
|
183
|
-
|
164
|
+
return str if charset.nil? || (charset == '') || str.nil? || (str == '')
|
165
|
+
return str.encode(charset) unless utf8?(str)
|
166
|
+
|
167
|
+
case charset
|
168
|
+
when /iso-2022-jp/i
|
184
169
|
utf8_to_jis(str)
|
185
|
-
|
170
|
+
when /shift_jis/i
|
186
171
|
utf8_to_sjis(str)
|
187
|
-
|
172
|
+
when /utf-8/i
|
188
173
|
str
|
189
|
-
else
|
190
|
-
str.encode(charset)
|
191
174
|
end
|
192
175
|
end
|
193
176
|
|
@@ -237,12 +220,10 @@ module Jpmobile
|
|
237
220
|
s.encode(to)
|
238
221
|
rescue ::Encoding::InvalidByteSequenceError, ::Encoding::UndefinedConversionError => e
|
239
222
|
# iPhone MailがISO-2022-JPに半角カナや①などのCP50220文字を含めてくる問題対策
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
raise e
|
245
|
-
end
|
223
|
+
raise e unless s.encoding == ::Encoding::ISO2022_JP
|
224
|
+
|
225
|
+
s.force_encoding(::Encoding::CP50220)
|
226
|
+
retry
|
246
227
|
end
|
247
228
|
end
|
248
229
|
|
@@ -256,13 +237,13 @@ module Jpmobile
|
|
256
237
|
def extract_charset(str)
|
257
238
|
case str
|
258
239
|
when /iso-2022-jp/i
|
259
|
-
|
240
|
+
'ISO-2022-JP'
|
260
241
|
when /shift_jis/i
|
261
|
-
|
242
|
+
'Shift_JIS'
|
262
243
|
when /utf-8/i
|
263
|
-
|
244
|
+
'UTF-8'
|
264
245
|
else
|
265
|
-
|
246
|
+
''
|
266
247
|
end
|
267
248
|
end
|
268
249
|
|
@@ -284,12 +265,15 @@ module Jpmobile
|
|
284
265
|
def ascii_8bit?(str)
|
285
266
|
detect_encoding(str) == BINARY
|
286
267
|
end
|
268
|
+
|
287
269
|
def utf8?(str)
|
288
270
|
detect_encoding(str) == UTF8
|
289
271
|
end
|
272
|
+
|
290
273
|
def shift_jis?(str)
|
291
274
|
detect_encoding(str) == SJIS
|
292
275
|
end
|
276
|
+
|
293
277
|
def jis?(str)
|
294
278
|
detect_encoding(str) == JIS
|
295
279
|
end
|
@@ -297,7 +281,7 @@ module Jpmobile
|
|
297
281
|
def fold_text(str, size = 15)
|
298
282
|
folded_texts = []
|
299
283
|
|
300
|
-
while texts = split_text(str, size)
|
284
|
+
while (texts = split_text(str, size)) && (texts.first.size != 0)
|
301
285
|
folded_texts << texts.first
|
302
286
|
str = texts.last
|
303
287
|
end
|
@@ -306,16 +290,16 @@ module Jpmobile
|
|
306
290
|
end
|
307
291
|
|
308
292
|
def split_text(str, size = 15)
|
309
|
-
return nil if str.nil?
|
293
|
+
return nil if str.nil? || (str == '')
|
310
294
|
|
311
|
-
[str[0..(size-1)], str[size..-1]]
|
295
|
+
[str[0..(size - 1)], str[size..-1]]
|
312
296
|
end
|
313
297
|
|
314
298
|
def invert_table(hash)
|
315
299
|
result = {}
|
316
300
|
hash.keys.each do |key|
|
317
301
|
if result[hash[key]]
|
318
|
-
if !key.
|
302
|
+
if !key.is_a?(Array) && !result[hash[key]].is_a?(Array) && result[hash[key]] > key
|
319
303
|
result[hash[key]] = key
|
320
304
|
end
|
321
305
|
else
|
@@ -336,7 +320,7 @@ module Jpmobile
|
|
336
320
|
end
|
337
321
|
|
338
322
|
_extract_charset = Jpmobile::Util.extract_charset(_str)
|
339
|
-
charset = _extract_charset unless _extract_charset.empty?
|
323
|
+
charset = _extract_charset unless _extract_charset.empty? || (_extract_charset == charset)
|
340
324
|
Jpmobile::Util.set_encoding(_str, charset)
|
341
325
|
end
|
342
326
|
end
|