jpmobile 0.1.0.pre.2 → 0.1.0.pre.3
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.
- data/README.rdoc +7 -0
- data/VERSION.yml +1 -1
- data/init.rb +1 -1
- data/jpmobile.gemspec +1 -1
- data/lib/jpmobile.rb +3 -0
- data/lib/jpmobile/hook_action_view.rb +18 -0
- data/lib/jpmobile/rack.rb +6 -0
- data/lib/jpmobile/rack/filter.rb +4 -1
- data/lib/jpmobile/trans_sid.rb +2 -2
- data/lib/jpmobile/util.rb +4 -4
- data/spec/rack/jpmobile/filter_spec.rb +27 -17
- data/spec/unit/util_spec.rb +5 -1
- data/test/rails/overrides/config/initializers/jpmobile_generator.rb +1 -0
- data/test/rails/overrides/spec/requests/trans_sid_spec.rb +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -135,6 +135,13 @@ jpmobileを読み込むとDoCoMo、Au、SoftBankの絵文字を透過的に扱
|
|
135
135
|
# Rack middleware を追加するメソッド
|
136
136
|
Rails.application.config.jpmobile.mobile_fiter
|
137
137
|
|
138
|
+
** 下記の設定を追加することで、<form> タグの accept-charset が変更される。
|
139
|
+
|
140
|
+
# <form accept-charset="Shift_JIS" ...> などに変更する
|
141
|
+
Rails.application.config.jpmobile.form_accept_charset_conversion = true
|
142
|
+
|
143
|
+
携帯電話上では特に問題とならない。PCブラウザでテストする際に問題となるためのオプション。
|
144
|
+
|
138
145
|
* Sinatra の場合は下記のように指定する。
|
139
146
|
|
140
147
|
$LOAD_PATH << './lib/jpmobile/lib'
|
data/VERSION.yml
CHANGED
data/init.rb
CHANGED
data/jpmobile.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jpmobile}
|
8
|
-
s.version = "0.1.0.pre.
|
8
|
+
s.version = "0.1.0.pre.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Yoji Shidara", "Shin-ichiro OGAWA"]
|
data/lib/jpmobile.rb
CHANGED
@@ -66,4 +66,22 @@ module ActionView
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
module Helpers
|
71
|
+
module FormTagHelper
|
72
|
+
private
|
73
|
+
def html_options_for_form(url_for_options, options, *parameters_for_url)
|
74
|
+
accept_charset = (Rails.application.config.jpmobile.form_accept_charset_conversion && request && request.mobile && request.mobile.default_charset) || "UTF-8"
|
75
|
+
|
76
|
+
options.stringify_keys.tap do |html_options|
|
77
|
+
html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
|
78
|
+
# The following URL is unescaped, this is just a hash of options, and it is the
|
79
|
+
# responsability of the caller to escape all the values.
|
80
|
+
html_options["action"] = url_for(url_for_options, *parameters_for_url)
|
81
|
+
html_options["accept-charset"] = accept_charset
|
82
|
+
html_options["data-remote"] = true if html_options.delete("remote")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
69
87
|
end
|
data/lib/jpmobile/rack.rb
CHANGED
data/lib/jpmobile/rack/filter.rb
CHANGED
@@ -21,7 +21,10 @@ module Jpmobile
|
|
21
21
|
charset = nil
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
body = response_to_body(response)
|
25
|
+
body = body.sub('<input name="_snowman" type="hidden" value="☃" />', ' ')
|
26
|
+
|
27
|
+
response, charset = mobile.to_external(body, type, charset)
|
25
28
|
|
26
29
|
if type and charset
|
27
30
|
env['Content-Type'] = "#{type}; charset=#{charset}"
|
data/lib/jpmobile/trans_sid.rb
CHANGED
@@ -7,9 +7,9 @@ module ParamsOverCookie
|
|
7
7
|
base.class_eval do
|
8
8
|
# cookie よりも params を先に見るパッチ
|
9
9
|
def extract_session_id_with_jpmobile(env)
|
10
|
-
request =
|
10
|
+
request = ActionDispatch::Request.new(env.dup)
|
11
11
|
if request.params[@key] and !@cookie_only
|
12
|
-
sid = request.params[@key]
|
12
|
+
sid = request.params[@key]
|
13
13
|
end
|
14
14
|
sid ||= request.cookies[@key]
|
15
15
|
sid
|
data/lib/jpmobile/util.rb
CHANGED
@@ -65,17 +65,17 @@ module Jpmobile
|
|
65
65
|
|
66
66
|
def utf8_to_sjis(utf8_str)
|
67
67
|
if utf8_str.respond_to?(:encode)
|
68
|
-
utf8_str.encode("Shift_JIS")
|
68
|
+
utf8_str.encode("Shift_JIS", :crlf_newline => true)
|
69
69
|
else
|
70
|
-
NKF.nkf("-m0 -x -Ws", utf8_str)
|
70
|
+
NKF.nkf("-m0 -x -Ws", utf8_str).gsub(/\n/, "\r\n")
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
def sjis_to_utf8(sjis_str)
|
75
75
|
if sjis_str.respond_to?(:encode)
|
76
|
-
sjis_str.encode("UTF-8")
|
76
|
+
sjis_str.encode("UTF-8", :universal_newline => true)
|
77
77
|
else
|
78
|
-
NKF.nkf("-m0 -x -Sw", sjis_str)
|
78
|
+
NKF.nkf("-m0 -x -Sw", sjis_str).gsub(/\r\n/, "\n")
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -7,7 +7,7 @@ describe Jpmobile::Rack::Filter do
|
|
7
7
|
|
8
8
|
context "漢字コード変換" do
|
9
9
|
before(:each) do
|
10
|
-
@utf8 = "
|
10
|
+
@utf8 = "ゆーてぃーえふえいとの\n日本語ですが何か"
|
11
11
|
@sjis = utf8_to_sjis(@utf8)
|
12
12
|
end
|
13
13
|
|
@@ -19,7 +19,7 @@ describe Jpmobile::Rack::Filter do
|
|
19
19
|
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
20
20
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8))).call(res)
|
21
21
|
res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
|
22
|
-
response_body(res) == @sjis
|
22
|
+
response_body(res).should == @sjis
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -31,7 +31,7 @@ describe Jpmobile::Rack::Filter do
|
|
31
31
|
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
32
32
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8))).call(res)
|
33
33
|
res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
|
34
|
-
response_body(res) == @sjis
|
34
|
+
response_body(res).should == @sjis
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -43,9 +43,19 @@ describe Jpmobile::Rack::Filter do
|
|
43
43
|
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
44
44
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8))).call(res)
|
45
45
|
res[1]['Content-Type'].should == "text/html"
|
46
|
-
response_body(res) == @utf8
|
46
|
+
response_body(res).should == @utf8
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
it "_snowman が出力されないこと" do
|
51
|
+
res = Rack::MockRequest.env_for(
|
52
|
+
"/",
|
53
|
+
"REQUEST_METHOD" => "GET",
|
54
|
+
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
55
|
+
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('<input name="_snowman" type="hidden" value="☃" />'))).call(res)
|
56
|
+
res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
|
57
|
+
response_body(res).should == " "
|
58
|
+
end
|
49
59
|
end
|
50
60
|
|
51
61
|
context "絵文字変換" do
|
@@ -61,7 +71,7 @@ describe Jpmobile::Rack::Filter do
|
|
61
71
|
@sjis = utf8_to_sjis(@utf8)
|
62
72
|
@docomo_emoji = sjis("\xf8\xac")
|
63
73
|
@au_emoji = sjis("\xf6\x6c")
|
64
|
-
@softbank_emoji = utf8("\
|
74
|
+
@softbank_emoji = utf8("\356\211\204")
|
65
75
|
end
|
66
76
|
|
67
77
|
context "docomo のとき" do
|
@@ -71,7 +81,7 @@ describe Jpmobile::Rack::Filter do
|
|
71
81
|
"REQUEST_METHOD" => "GET",
|
72
82
|
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
73
83
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_docomo_cr))).call(res)
|
74
|
-
response_body(res) == @sjis + @docomo_emoji
|
84
|
+
response_body(res).should == @sjis + @docomo_emoji
|
75
85
|
end
|
76
86
|
|
77
87
|
it "docomo のUTF-8絵文字が変換されること" do
|
@@ -80,7 +90,7 @@ describe Jpmobile::Rack::Filter do
|
|
80
90
|
"REQUEST_METHOD" => "GET",
|
81
91
|
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
82
92
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_docomo_utf8))).call(res)
|
83
|
-
response_body(res) == @sjis + @docomo_emoji
|
93
|
+
response_body(res).should == @sjis + @docomo_emoji
|
84
94
|
end
|
85
95
|
|
86
96
|
it "au のUTF-8絵文字が変換されること" do
|
@@ -89,7 +99,7 @@ describe Jpmobile::Rack::Filter do
|
|
89
99
|
"REQUEST_METHOD" => "GET",
|
90
100
|
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
91
101
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_au_utf8))).call(res)
|
92
|
-
response_body(res) == @sjis + @docomo_emoji
|
102
|
+
response_body(res).should == @sjis + @docomo_emoji
|
93
103
|
end
|
94
104
|
|
95
105
|
it "softbank のUTF-8絵文字が変換されること" do
|
@@ -98,7 +108,7 @@ describe Jpmobile::Rack::Filter do
|
|
98
108
|
"REQUEST_METHOD" => "GET",
|
99
109
|
'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
|
100
110
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_softbank_utf8))).call(res)
|
101
|
-
response_body(res) == @sjis + @docomo_emoji
|
111
|
+
response_body(res).should == @sjis + @docomo_emoji
|
102
112
|
end
|
103
113
|
end
|
104
114
|
|
@@ -109,7 +119,7 @@ describe Jpmobile::Rack::Filter do
|
|
109
119
|
"REQUEST_METHOD" => "GET",
|
110
120
|
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
111
121
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_au_cr))).call(res)
|
112
|
-
response_body(res) == @sjis + @au_emoji
|
122
|
+
response_body(res).should == @sjis + @au_emoji
|
113
123
|
end
|
114
124
|
|
115
125
|
it "docomo のUTF-8絵文字が変換されること" do
|
@@ -118,7 +128,7 @@ describe Jpmobile::Rack::Filter do
|
|
118
128
|
"REQUEST_METHOD" => "GET",
|
119
129
|
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
120
130
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_docomo_utf8))).call(res)
|
121
|
-
response_body(res) == @sjis + @au_emoji
|
131
|
+
response_body(res).should == @sjis + @au_emoji
|
122
132
|
end
|
123
133
|
|
124
134
|
it "au のUTF-8絵文字が変換されること" do
|
@@ -127,7 +137,7 @@ describe Jpmobile::Rack::Filter do
|
|
127
137
|
"REQUEST_METHOD" => "GET",
|
128
138
|
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
129
139
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_au_utf8))).call(res)
|
130
|
-
response_body(res) == @sjis + @au_emoji
|
140
|
+
response_body(res).should == @sjis + @au_emoji
|
131
141
|
end
|
132
142
|
|
133
143
|
it "softbank のUTF-8絵文字が変換されること" do
|
@@ -136,7 +146,7 @@ describe Jpmobile::Rack::Filter do
|
|
136
146
|
"REQUEST_METHOD" => "GET",
|
137
147
|
'HTTP_USER_AGENT' => "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0")
|
138
148
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_softbank_utf8))).call(res)
|
139
|
-
response_body(res) == @sjis + @au_emoji
|
149
|
+
response_body(res).should == @sjis + @au_emoji
|
140
150
|
end
|
141
151
|
end
|
142
152
|
|
@@ -147,7 +157,7 @@ describe Jpmobile::Rack::Filter do
|
|
147
157
|
"REQUEST_METHOD" => "GET",
|
148
158
|
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
149
159
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_softbank_cr))).call(res)
|
150
|
-
response_body(res) == @utf8 + @softbank_emoji
|
160
|
+
response_body(res).should == @utf8 + @softbank_emoji
|
151
161
|
end
|
152
162
|
|
153
163
|
it "docomo のUTF-8絵文字が変換されること" do
|
@@ -156,7 +166,7 @@ describe Jpmobile::Rack::Filter do
|
|
156
166
|
"REQUEST_METHOD" => "GET",
|
157
167
|
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
158
168
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_docomo_utf8))).call(res)
|
159
|
-
response_body(res) == @utf8 + @softbank_emoji
|
169
|
+
response_body(res).should == @utf8 + @softbank_emoji
|
160
170
|
end
|
161
171
|
|
162
172
|
it "au のUTF-8絵文字が変換されること" do
|
@@ -165,7 +175,7 @@ describe Jpmobile::Rack::Filter do
|
|
165
175
|
"REQUEST_METHOD" => "GET",
|
166
176
|
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
167
177
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_au_utf8))).call(res)
|
168
|
-
response_body(res) == @utf8 + @softbank_emoji
|
178
|
+
response_body(res).should == @utf8 + @softbank_emoji
|
169
179
|
end
|
170
180
|
|
171
181
|
it "softbank のUTF-8絵文字が変換されること" do
|
@@ -174,7 +184,7 @@ describe Jpmobile::Rack::Filter do
|
|
174
184
|
"REQUEST_METHOD" => "GET",
|
175
185
|
'HTTP_USER_AGENT' => "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
|
176
186
|
res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@utf8 + @emoji_softbank_utf8))).call(res)
|
177
|
-
response_body(res) == @utf8 + @softbank_emoji
|
187
|
+
response_body(res).should == @utf8 + @softbank_emoji
|
178
188
|
end
|
179
189
|
end
|
180
190
|
end
|
data/spec/unit/util_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'stringio'
|
3
|
+
require 'nkf'
|
3
4
|
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
4
5
|
|
5
6
|
describe Jpmobile::Util, ".deep_apply" do
|
@@ -26,5 +27,8 @@ describe Jpmobile::Util, ".deep_apply" do
|
|
26
27
|
string_io = StringIO.new('test')
|
27
28
|
Jpmobile::Util.deep_apply(string_io) {|obj| obj }.should equal(string_io)
|
28
29
|
end
|
29
|
-
end
|
30
30
|
|
31
|
+
it "utf8_to_sjis で改行コードが CRLF に変更されること" do
|
32
|
+
Jpmobile::Util.utf8_to_sjis("UTF8\nTEXT\n").should == Jpmobile::Util.sjis("UTF8\r\nTEXT\r\n")
|
33
|
+
end
|
34
|
+
end
|
@@ -131,12 +131,12 @@ describe TransSidAlwaysAndSessionOffController, "という trans_sid :always が
|
|
131
131
|
end
|
132
132
|
|
133
133
|
# NOTE: 3.0.0RC では accept-charset は UTF-8 で埋め込まれるので保留
|
134
|
-
describe_mobile_with_ua "DoCoMo/2.0 SH902i(c100;TB;W24H12)", "
|
134
|
+
describe_mobile_with_ua "DoCoMo/2.0 SH902i(c100;TB;W24H12)", "Shift_JIS" do
|
135
135
|
it_should_behave_like "trans_sid が起動するとき"
|
136
136
|
end
|
137
137
|
|
138
138
|
# NOTE: 3.0.0RC では accept-charset は UTF-8 で埋め込まれるので保留
|
139
|
-
describe_mobile_with_ua "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0", "
|
139
|
+
describe_mobile_with_ua "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0", "Shift_JIS" do
|
140
140
|
it_should_behave_like "trans_sid が起動しないとき"
|
141
141
|
end
|
142
142
|
|