jpmobile 0.1.2 → 0.1.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/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'jeweler'
4
+ gem 'rails', '>= 3.0.1'
5
+ gem 'rspec', '>= 2.0.0'
6
+ gem 'rspec-rails', '>= 2.0.0'
7
+ gem 'webrat'
8
+ gem 'geokit'
9
+ gem 'sqlite3-ruby'
10
+ gem 'hpricot'
data/README.rdoc CHANGED
@@ -98,7 +98,6 @@
98
98
  end
99
99
 
100
100
  class MobileController < ApplicationController
101
- mobile_filter
102
101
  end
103
102
 
104
103
  === 位置情報の取得
@@ -173,10 +172,14 @@ jpmobileを読み込むとDoCoMo、Au、SoftBankの絵文字を透過的に扱
173
172
  Rails のみ半角・全角の自動変換フィルターが用意されている。用いるには
174
173
 
175
174
  class MyController
176
- mobile_filter :hankaku=>true
175
+ hankaku_filter
177
176
  end
178
177
 
179
- と指定する。
178
+ と指定する。またtextareaやhidden/text/passwordのinputタグで半角に変換したくない場合は :input => true を指定する。
179
+
180
+ class MyController
181
+ hankaku_filter :input => true
182
+ end
180
183
 
181
184
  Jpmobile内では、各キャリアの絵文字はUnicode私的領域上にマッピングされ、管理される。
182
185
  このとき、DoCoMo、Auは公式サイト記載のマッピングが使用される。
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 2
4
+ :patch: 3
5
5
  :build:
@@ -1,15 +1,19 @@
1
1
  # -*- coding: utf-8 -*-
2
- # = 文字コードフィルタ
2
+ # = 半角変換フィルター
3
3
  # thanks to masuidrive <masuidrive (at) masuidrive.jp>
4
4
 
5
5
  class ActionController::Base #:nodoc:
6
+ def self.hankaku_filter(options={})
7
+ options = {:input => false}.update(options)
8
+
9
+ before_filter lambda {|controller| Jpmobile::HankakuFilter.before(controller, options)}
10
+ after_filter lambda {|controller| Jpmobile::HankakuFilter.after(controller, options)}
11
+ end
12
+
6
13
  def self.mobile_filter(options={})
7
- options = {:emoticon=>true, :hankaku=>false}.update(options)
14
+ STDERR.puts "Method mobile_filter is now deprecated. Use hankaku_filter instead for Hankaku-conversion."
8
15
 
9
- if options[:hankaku]
10
- before_filter lambda {|controller| Jpmobile::HankakuFilter.before(controller)}
11
- after_filter lambda {|controller| Jpmobile::HankakuFilter.after(controller)}
12
- end
16
+ self.hankaku_filter(options)
13
17
  end
14
18
  end
15
19
 
@@ -26,28 +30,44 @@ module Jpmobile
26
30
  [nil, "text/html", "application/xhtml+xml"].include?(controller.response.content_type)
27
31
  end
28
32
 
29
- def before(controller)
33
+ def before(controller, options = {})
30
34
  if apply_incoming?(controller)
31
35
  Util.deep_apply(controller.params) do |value|
32
- value = to_internal(value)
36
+ value = to_internal(value, options)
33
37
  end
34
38
  end
35
39
  end
36
40
  # 内部コードから外部コードに変換
37
- def after(controller)
41
+ def after(controller, options = {})
38
42
  if apply_outgoing?(controller) and controller.response.body.is_a?(String)
39
- controller.response.body = to_external(controller.response.body)
43
+ controller.response.body = to_external(controller.response.body, options)
40
44
  end
41
45
  end
42
46
 
43
- @@internal = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゛ ゜ ー 。 「 」 、 ・).freeze
44
- @@external = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゙ ゚ ー 。 「 」 、 ・).freeze
45
- def to_internal(str)
47
+ @@internal = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゛ ゜ ー 。 「 」 、 ・ ! ?).freeze
48
+ @@external = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゙ ゚ ー 。 「 」 、 ・ ! ?).freeze
49
+ def to_internal(str, options = {})
46
50
  filter(str, @@external, @@internal)
47
51
  end
48
- def to_external(str)
49
- filter(str, @@internal, @@external)
52
+ def to_external(str, options = {})
53
+ unless options[:input]
54
+ filter(str, @@internal, @@external)
55
+ else
56
+ encoding = (str =~ /^\s*<[^Hh>]*html/) and str.respond_to?(:encoding)
57
+ nokogiri_klass =
58
+ (str =~ /^\s*<[^Hh>]*html/) ? Nokogiri::HTML::Document : Nokogiri::HTML::DocumentFragment
59
+ doc = if encoding
60
+ nokogiri_klass.parse(str, nil, "UTF-8")
61
+ else
62
+ nokogiri_klass.parse(str)
63
+ end
64
+
65
+ doc = convert_text_content(doc)
66
+
67
+ doc.to_html
68
+ end
50
69
  end
70
+
51
71
  def filter(str, from, to)
52
72
  str = str.clone
53
73
 
@@ -69,5 +89,25 @@ module Jpmobile
69
89
 
70
90
  str
71
91
  end
92
+
93
+ # 再帰的に探す
94
+ def convert_text_content(document)
95
+ document.children.each do |element|
96
+ if element.kind_of?(Nokogiri::XML::Text)
97
+ unless element.parent.node_name == "textarea"
98
+ # textarea 以外のテキストなら content を変換
99
+ element.content = filter(element.content, @@internal, @@external)
100
+ end
101
+ elsif element.node_name == "input" and ["submit", "reset", "button"].include?(element["type"])
102
+ # テキスト以外でもボタンの value は変換
103
+ element["value"] = filter(element["value"], @@internal, @@external)
104
+ elsif element.children.any?
105
+ # 子要素があれば再帰的に変換
106
+ element = convert_text_content(element)
107
+ end
108
+ end
109
+
110
+ document
111
+ end
72
112
  end
73
113
  end
@@ -22,7 +22,8 @@ module Jpmobile
22
22
  end
23
23
 
24
24
  body = response_to_body(response)
25
- body = body.sub('<input name="utf8" type="hidden" value="&#x2713;" />', ' ')
25
+ body = body.gsub(/<input name="utf8" type="hidden" value="#{[0x2713].pack("U")}"[^>]*?>/, ' ')
26
+ body = body.gsub(/<input name="utf8" type="hidden" value="&#x2713;"[^>]*?>/, ' ')
26
27
 
27
28
  response, charset = mobile.to_external(body, type, charset)
28
29
 
@@ -61,7 +61,7 @@ module ActionController
61
61
  alias_method_chain :redirect_to, :jpmobile
62
62
  end
63
63
 
64
- class Base #:nodoc:
64
+ class Metal #:nodoc:
65
65
  class_inheritable_accessor :trans_sid_mode
66
66
 
67
67
  class << self
@@ -128,6 +128,6 @@ module Jpmobile::TransSid #:nodoc:
128
128
  return unless request # for test process
129
129
  return unless apply_trans_sid?
130
130
  return unless jpmobile_session_id
131
- response.body.gsub!(%r{(</form>)}i, sid_hidden_field_tag+'\1')
131
+ response.body = response.body.gsub(%r{(</form>)}i, sid_hidden_field_tag+'\1')
132
132
  end
133
133
  end
data/lib/jpmobile/util.rb CHANGED
@@ -79,6 +79,14 @@ module Jpmobile
79
79
  end
80
80
  end
81
81
 
82
+ def regexp_utf8_to_sjis(utf8_str)
83
+ if Object.const_defined?(:Encoding)
84
+ Regexp.compile(Regexp.escape(utf8_to_sjis(utf8_str)))
85
+ else
86
+ Regexp.compile(Regexp.escape(utf8_to_sjis(utf8_str),"s"),nil,'s')
87
+ end
88
+ end
89
+
82
90
  def hash_to_utf8(hash)
83
91
  new_hash = {}
84
92
  hash.each do |keu, value|
@@ -39,7 +39,7 @@ namespace :test do
39
39
  task :rails, [:versions] do |t, args|
40
40
  rails_root = "test/rails/rails_root"
41
41
  relative_root = "../../../"
42
- rails_versions = args.versions.split("/") rescue ["3.0.0.rc"]
42
+ rails_versions = args.versions.split("/") rescue ["3.0.2"]
43
43
 
44
44
  puts "Running tests in Rails #{rails_versions.join(', ')}"
45
45
 
@@ -53,7 +53,7 @@ namespace :test do
53
53
  # setup jpmobile
54
54
  plugin_path = File.join(rails_root, 'vendor', 'plugins', 'jpmobile')
55
55
  FileUtils.mkdir_p(plugin_path)
56
- FileList["*"].exclude("test").each do |file|
56
+ FileList["*"].exclude("test").exclude("spec").each do |file|
57
57
  FileUtils.cp_r(file, plugin_path)
58
58
  end
59
59
 
@@ -98,7 +98,7 @@ END
98
98
  # ruby "-S bundle install"
99
99
  ruby "-S rake db:migrate test"
100
100
  ruby "-S rake spec"
101
- # ruby "-S rspec -b --color spec/requests/trans_sid_spec.rb"
101
+ # 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の中では半角に変換されないこと'"
102
102
 
103
103
  cd relative_root
104
104
  end
@@ -50,8 +50,8 @@ describe Jpmobile::Rack::MobileCarrier, "au" do
50
50
  "QUERY_STRING" => "ver=1&datum=0&unit=0&lat=%2b43.05.08.95&lon=%2b141.20.25.99&alt=155&time=20060521010328&smaj=76&smin=62&vert=65&majaa=49&fm=1")
51
51
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
52
52
 
53
- env['rack.jpmobile'].position.lat.should be_close(43.08581944, 1e-7)
54
- env['rack.jpmobile'].position.lon.should be_close(141.3405528, 1e-7)
53
+ env['rack.jpmobile'].position.lat.should be_within(1e-7).of(43.08581944)
54
+ env['rack.jpmobile'].position.lon.should be_within(1e-7).of(141.3405528)
55
55
  end
56
56
 
57
57
  it "緯度経度を取得できること(dgree_tokyo)" do
@@ -61,8 +61,8 @@ describe Jpmobile::Rack::MobileCarrier, "au" do
61
61
  "QUERY_STRING" => "ver=1&datum=1&unit=1&lat=%2b43.07475&lon=%2b141.34259&alt=8&time=20061017182825&smaj=113&smin=76&vert=72&majaa=108&fm=1")
62
62
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
63
63
 
64
- env['rack.jpmobile'].position.lat.should be_close(43.07719289, 1e-4)
65
- env['rack.jpmobile'].position.lon.should be_close(141.3389013, 1e-4)
64
+ env['rack.jpmobile'].position.lat.should be_within(1e-4).of(43.07719289)
65
+ env['rack.jpmobile'].position.lon.should be_within(1e-4).of(141.3389013)
66
66
  end
67
67
 
68
68
  it "緯度経度を取得できること(dgree_tokyo)" do
@@ -72,8 +72,8 @@ describe Jpmobile::Rack::MobileCarrier, "au" do
72
72
  "QUERY_STRING" => "ver=1&datum=1&unit=1&lat=%2b43.07475&lon=%2b141.34259&alt=8&time=20061017182825&smaj=113&smin=76&vert=72&majaa=108&fm=1")
73
73
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
74
74
 
75
- env['rack.jpmobile'].position.lat.should be_close(43.07719289, 1e-4)
76
- env['rack.jpmobile'].position.lon.should be_close(141.3389013, 1e-4)
75
+ env['rack.jpmobile'].position.lat.should be_within(1e-4).of(43.07719289)
76
+ env['rack.jpmobile'].position.lon.should be_within(1e-4).of(141.3389013)
77
77
  end
78
78
 
79
79
  it "緯度経度を取得できること(dms_tokyo)" do
@@ -83,8 +83,8 @@ describe Jpmobile::Rack::MobileCarrier, "au" do
83
83
  "QUERY_STRING" => "datum=tokyo&unit=dms&lat=43.04.55.00&lon=141.20.50.75")
84
84
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
85
85
 
86
- env['rack.jpmobile'].position.lat.should be_close(43.08194444, 1e-7)
87
- env['rack.jpmobile'].position.lon.should be_close(141.3474306, 1e-7)
86
+ env['rack.jpmobile'].position.lat.should be_within(1e-7).of(43.08194444)
87
+ env['rack.jpmobile'].position.lon.should be_within(1e-7).of(141.3474306)
88
88
  end
89
89
 
90
90
  it "緯度経度を取得できること(antenna)" do
@@ -94,8 +94,8 @@ describe Jpmobile::Rack::MobileCarrier, "au" do
94
94
  "QUERY_STRING" => "datum=tokyo&unit=dms&lat=43.04.55.00&lon=141.20.50.75")
95
95
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
96
96
 
97
- env['rack.jpmobile'].position.lat.should be_close(43.08194444, 1e-7)
98
- env['rack.jpmobile'].position.lon.should be_close(141.3474306, 1e-7)
97
+ env['rack.jpmobile'].position.lat.should be_within(1e-7).of(43.08194444)
98
+ env['rack.jpmobile'].position.lon.should be_within(1e-7).of(141.3474306)
99
99
  end
100
100
 
101
101
  it "GeoKit がある場合に取得できること" do
@@ -137,8 +137,8 @@ describe Jpmobile::Rack::MobileCarrier, "docomo" do
137
137
 
138
138
  env['rack.jpmobile'].areacode.should == "00100"
139
139
 
140
- env['rack.jpmobile'].position.lat.should be_close(35.00988889, 1e-7)
141
- env['rack.jpmobile'].position.lon.should be_close(135.6932222, 1e-7)
140
+ env['rack.jpmobile'].position.lat.should be_within(1e-7).of(35.00988889)
141
+ env['rack.jpmobile'].position.lon.should be_within(1e-7).of(135.6932222)
142
142
  end
143
143
  end
144
144
 
@@ -150,8 +150,8 @@ describe Jpmobile::Rack::MobileCarrier, "docomo" do
150
150
  "QUERY_STRING" => "lat=%2B35.00.35.600&lon=%2B135.41.35.600&geo=wgs84&x-acc=3")
151
151
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
152
152
 
153
- env['rack.jpmobile'].position.lat.should be_close(35.00988889, 1e-7)
154
- env['rack.jpmobile'].position.lon.should be_close(135.6932222, 1e-7)
153
+ env['rack.jpmobile'].position.lat.should be_within(1e-7).of(35.00988889)
154
+ env['rack.jpmobile'].position.lon.should be_within(1e-7).of(135.6932222)
155
155
  end
156
156
 
157
157
  # DoCoMo, 903i, GPS
@@ -164,8 +164,8 @@ describe Jpmobile::Rack::MobileCarrier, "docomo" do
164
164
  "QUERY_STRING" => "lat=%2B35.00.35.600&lon=%2B135.41.35.600&geo=WGS84&alt=%2B64.000&x-acc=1")
165
165
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
166
166
 
167
- env['rack.jpmobile'].position.lat.should be_close(35.00988889, 1e-7)
168
- env['rack.jpmobile'].position.lon.should be_close(135.6932222, 1e-7)
167
+ env['rack.jpmobile'].position.lat.should be_within(1e-7).of(35.00988889)
168
+ env['rack.jpmobile'].position.lon.should be_within(1e-7).of(135.6932222)
169
169
  end
170
170
  end
171
171
 
@@ -48,11 +48,29 @@ describe Jpmobile::Rack::Filter do
48
48
  end
49
49
 
50
50
  it "_snowman が出力されないこと" do
51
- res = Rack::MockRequest.env_for(
51
+ req = Rack::MockRequest.env_for(
52
52
  "/",
53
53
  "REQUEST_METHOD" => "GET",
54
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="utf8" type="hidden" value="&#x2713;" />'))).call(res)
55
+ res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('<input name="utf8" type="hidden" value="&#x2713;" />'))).call(req)
56
+ res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
57
+ response_body(res).should == " "
58
+
59
+ res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('<input name="utf8" type="hidden" value="&#x2713;">'))).call(req)
60
+ res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
61
+ response_body(res).should == " "
62
+ end
63
+
64
+ it "Nokogiri 経由の _snowman が出力されないこと" do
65
+ req = Rack::MockRequest.env_for(
66
+ "/",
67
+ "REQUEST_METHOD" => "GET",
68
+ 'HTTP_USER_AGENT' => 'DoCoMo/2.0 SH906i(c100;TB;W24H16)')
69
+ res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new("<input name=\"utf8\" type=\"hidden\" value=\"#{[10003].pack("U")}\" />"))).call(req)
70
+ res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
71
+ response_body(res).should == " "
72
+
73
+ res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new("<input name=\"utf8\" type=\"hidden\" value=\"#{[10003].pack("U")}\">"))).call(req)
56
74
  res[1]['Content-Type'].should == "text/html; charset=Shift_JIS"
57
75
  response_body(res).should == " "
58
76
  end
@@ -57,8 +57,8 @@ describe Jpmobile::Rack::MobileCarrier, "softbank" do
57
57
  "QUERY_STRING" => "pos=N43.3.18.42E141.21.1.88&geo=wgs84&x-acr=1")
58
58
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
59
59
 
60
- env['rack.jpmobile'].position.lat.should be_close(43.05511667, 1e-7)
61
- env['rack.jpmobile'].position.lon.should be_close(141.3505222, 1e-7)
60
+ env['rack.jpmobile'].position.lat.should be_within(1e-7).of(43.05511667)
61
+ env['rack.jpmobile'].position.lon.should be_within(1e-7).of(141.3505222)
62
62
  env['rack.jpmobile'].position.options['pos'].should == "N43.3.18.42E141.21.1.88"
63
63
  env['rack.jpmobile'].position.options['geo'].should == "wgs84"
64
64
  env['rack.jpmobile'].position.options['x-acr'].should == "1"
@@ -38,8 +38,8 @@ describe Jpmobile::Rack::MobileCarrier, "willcom" do
38
38
  "QUERY_STRING" => "pos=N43.04.34.049E141.21.03.279")
39
39
  env = Jpmobile::Rack::MobileCarrier.new(UnitApplication.new).call(res)[1]
40
40
 
41
- env['rack.jpmobile'].position.lat.should be_close(43.078568, 1e-4)
42
- env['rack.jpmobile'].position.lon.should be_close(141.347223, 1e-4)
41
+ env['rack.jpmobile'].position.lat.should be_within(1e-4).of(43.078568)
42
+ env['rack.jpmobile'].position.lon.should be_within(1e-4).of(141.347223)
43
43
  end
44
44
  end
45
45
 
@@ -0,0 +1,33 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '>= 3.0.0'
4
+
5
+ # Bundle edge Rails instead:
6
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+
8
+ gem 'sqlite3-ruby', :require => 'sqlite3'
9
+
10
+ gem 'geokit'
11
+ gem 'hpricot'
12
+
13
+ # Use unicorn as the web server
14
+ # gem 'unicorn'
15
+
16
+ # Deploy with Capistrano
17
+ # gem 'capistrano'
18
+
19
+ # To use debugger
20
+ # gem 'ruby-debug'
21
+
22
+ # Bundle the extra gems:
23
+ # gem 'bj'
24
+ # gem 'nokogiri', '1.4.1'
25
+ # gem 'sqlite3-ruby', :require => 'sqlite3'
26
+ # gem 'aws-s3', :require => 'aws/s3'
27
+
28
+ # Bundle gems for certain environments:
29
+ group :development, :test do
30
+ gem "rspec", ">= 2.0.0"
31
+ gem "rspec-rails", ">= 2.0.0"
32
+ gem 'webrat'
33
+ end
@@ -1,3 +1,3 @@
1
1
  class FilterController < FilterControllerBase
2
- mobile_filter
2
+ # mobile_filter
3
3
  end
@@ -16,4 +16,10 @@ class FilterControllerBase < ApplicationController
16
16
  def rawdata
17
17
  send_data "アブラカダブラ", :type => 'application/octet-stream'
18
18
  end
19
+ def textarea
20
+ render :text => '<textarea hoge="fuu">アブラカダブラ</textarea>'
21
+ end
22
+ def input_tag
23
+ render :text => '<input hoge="fuu" value="アブラカダブラ" />'
24
+ end
19
25
  end
@@ -1,3 +1,3 @@
1
1
  class HankakuFilterController < FilterControllerBase
2
- mobile_filter :hankaku => true
2
+ hankaku_filter
3
3
  end
@@ -0,0 +1,7 @@
1
+ class HankakuInputFilterController < FilterControllerBase
2
+ hankaku_filter :input => true
3
+
4
+ def index_xhtml
5
+ render "index_xhtml", :layout => "xhtml"
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+ class TransSidMetalController < ActionController::Metal
3
+ include ActionController::RackDelegation
4
+ include ActionController::UrlFor
5
+ include ActionController::Redirecting
6
+ include Rails.application.routes.url_helpers
7
+
8
+ # 事前にセッションを作成しないと trans_sid が有効にならない
9
+ # before_filter :session_init
10
+ # trans_sid :always
11
+
12
+ def redirect
13
+ redirect_to('/')
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/1.1) 1.0//EN" "i-xhtml_4ja_10.dtd">
2
+ <?xml version='1.0' encoding='Shift_JIS' ?>
3
+ <html xml:lang="ja" xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <meta content="width=device-width; initial-scale=1.0" name="viewport">
6
+ <meta content="application/xhtml+xml; charset=Shift_JIS" http-equiv="Content-Type">
7
+ <title>じぇいぴぃもばいる</title>
8
+ </head>
9
+ <body>
10
+ <%= yield -%>
11
+ </body>
12
+ </html>
@@ -1,4 +1,4 @@
1
- RailsRoot::Application.routes.draw do |map|
1
+ RailsRoot::Application.routes.draw do
2
2
  resources :users
3
3
  namespace :admin do
4
4
  resources :users
@@ -3,6 +3,29 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
4
  describe "jpmobile integration spec" do
5
5
  include Jpmobile::Util
6
+
7
+ shared_examples_for "hankaku_filter :input => true のとき" do
8
+ it "はtextareaの中では半角に変換されないこと" do
9
+ get "/#{@controller}/textarea", {}, {"HTTP_USER_AGENT" => @user_agent}
10
+ body.should == send(@conversion_method, '<textarea hoge="fuu">アブラカダブラ</textarea>')
11
+ end
12
+ it "はinputのvalueの中では半角に変換されないこと" do
13
+ get "/#{@controller}/input_tag", {}, {"HTTP_USER_AGENT" => @user_agent}
14
+ body.should == send(@conversion_method, '<input hoge="fuu" value="アブラカダブラ">')
15
+ end
16
+ end
17
+
18
+ shared_examples_for "hankaku_filter :input => false のとき" do
19
+ it "はtextareaの中でも半角に変換されること" do
20
+ get "/#{@controller}/textarea", {}, {"HTTP_USER_AGENT" => @user_agent}
21
+ body.should == send(@conversion_method, '<textarea hoge="fuu">アブラカダブラ</textarea>')
22
+ end
23
+ it "はinputのvalueの中も半角に変換されること" do
24
+ get "/#{@controller}/input_tag", {}, {"HTTP_USER_AGENT" => @user_agent}
25
+ body.should == send(@conversion_method, '<input hoge="fuu" value="アブラカダブラ" />')
26
+ end
27
+ end
28
+
6
29
  shared_examples_for "文字コードフィルタが動作しているとき" do
7
30
  it "はhtml以外は変換しないこと" do
8
31
  get "/#{@controller}/rawdata", {}, {"HTTP_USER_AGENT" => @user_agent}
@@ -157,15 +180,42 @@ describe "jpmobile integration spec" do
157
180
  before do
158
181
  @user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
159
182
  @controller = "hankaku_filter"
183
+ @conversion_method = :utf8_to_sjis
160
184
  end
161
185
  it_should_behave_like "Shift_JISで通信する端末との通信(半角変換付き)"
186
+ it_should_behave_like "hankaku_filter :input => false のとき"
162
187
  end
163
188
 
164
189
  describe HankakuFilterController, "SoftBank 910T からのアクセス" do
165
190
  before do
166
191
  @user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
167
192
  @controller = "hankaku_filter"
193
+ @conversion_method = :utf8
194
+ end
195
+ it_should_behave_like "UTF-8で通信する端末との通信(半角変換付き)"
196
+ it_should_behave_like "hankaku_filter :input => false のとき"
197
+ end
198
+
199
+ #
200
+ # 半角フィルタ(input付き)
201
+ #
202
+ describe HankakuInputFilterController, "DoCoMo SH902i からのアクセス" do
203
+ before do
204
+ @user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
205
+ @controller = "hankaku_input_filter"
206
+ @conversion_method = :utf8_to_sjis
207
+ end
208
+ it_should_behave_like "Shift_JISで通信する端末との通信(半角変換付き)"
209
+ it_should_behave_like "hankaku_filter :input => true のとき"
210
+ end
211
+
212
+ describe HankakuInputFilterController, "SoftBank 910T からのアクセス" do
213
+ before do
214
+ @user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
215
+ @controller = "hankaku_input_filter"
216
+ @conversion_method = :utf8
168
217
  end
169
218
  it_should_behave_like "UTF-8で通信する端末との通信(半角変換付き)"
219
+ it_should_behave_like "hankaku_filter :input => true のとき"
170
220
  end
171
221
  end
@@ -49,6 +49,10 @@ describe "trans_sid functional" do
49
49
 
50
50
  res.response.body.should =~ /<a href=\"\/.+?\/link\?_session_id=[a-zA-Z0-9]{32}\">linkto<\/a>/
51
51
  end
52
+ it "で form内にhiddenが差し込まれる" do
53
+ res = get_with_session(@controller, "form", @user_agent)
54
+ res.response.body.should =~ /<input type=\"hidden\" name=\".+\" value=\"[a-zA-Z0-9]{32}\"/
55
+ end
52
56
  it "で form の自動書き換えが行われる" do
53
57
  res = get_with_session(@controller, "form", @user_agent)
54
58
 
@@ -140,6 +144,20 @@ describe "trans_sid functional" do
140
144
  it_should_behave_like "trans_sid が起動するとき"
141
145
  end
142
146
 
147
+ describe TransSidMetalController, "という ActionController::Metal のコントローラ" do
148
+ before(:each) do
149
+ @controller = "trans_sid_metal"
150
+ @user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)"
151
+ @charset = "UTF-8"
152
+ end
153
+
154
+ it "で redirect_to がエラーにならない" do
155
+ res = get_with_session(@controller, "redirect", @user_agent)
156
+
157
+ res.response.should be_redirect
158
+ end
159
+ end
160
+
143
161
  describe TransSidMobileController, "という trans_sid :mobile が指定されているコントローラ" do
144
162
  before(:each) do
145
163
  @controller = "trans_sid_mobile"
@@ -26,6 +26,7 @@ RSpec.configure do |config|
26
26
  config.use_transactional_fixtures = true
27
27
  config.include Webrat::HaveTagMatcher
28
28
  config.include Jpmobile::Util
29
+ config.before(:each) { Webrat.configuration.mode = :rails }
29
30
  end
30
31
 
31
32
  require 'pp'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Yoji Shidara
@@ -15,13 +15,122 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-16 00:00:00 +09:00
18
+ date: 2010-11-16 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: jeweler
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ prerelease: false
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rails
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 3
43
+ - 0
44
+ - 1
45
+ version: 3.0.1
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id002
21
49
  - !ruby/object:Gem::Dependency
22
50
  name: rspec
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 2
58
+ - 0
59
+ - 0
60
+ version: 2.0.0
61
+ type: :runtime
23
62
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rspec-rails
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 2
73
+ - 0
74
+ - 0
75
+ version: 2.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: webrat
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ name: geokit
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ name: sqlite3-ruby
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ type: :runtime
116
+ prerelease: false
117
+ version_requirements: *id007
118
+ - !ruby/object:Gem::Dependency
119
+ name: hpricot
120
+ requirement: &id008 !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ type: :runtime
129
+ prerelease: false
130
+ version_requirements: *id008
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec
133
+ requirement: &id009 !ruby/object:Gem::Requirement
25
134
  none: false
26
135
  requirements:
27
136
  - - "="
@@ -34,11 +143,11 @@ dependencies:
34
143
  - 17
35
144
  version: 2.0.0.beta.17
36
145
  type: :development
37
- version_requirements: *id001
146
+ prerelease: false
147
+ version_requirements: *id009
38
148
  - !ruby/object:Gem::Dependency
39
149
  name: rspec-rails
40
- prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
150
+ requirement: &id010 !ruby/object:Gem::Requirement
42
151
  none: false
43
152
  requirements:
44
153
  - - "="
@@ -51,11 +160,11 @@ dependencies:
51
160
  - 17
52
161
  version: 2.0.0.beta.17
53
162
  type: :development
54
- version_requirements: *id002
163
+ prerelease: false
164
+ version_requirements: *id010
55
165
  - !ruby/object:Gem::Dependency
56
166
  name: jeweler
57
- prerelease: false
58
- requirement: &id003 !ruby/object:Gem::Requirement
167
+ requirement: &id011 !ruby/object:Gem::Requirement
59
168
  none: false
60
169
  requirements:
61
170
  - - ">="
@@ -66,7 +175,8 @@ dependencies:
66
175
  - 0
67
176
  version: 1.4.0
68
177
  type: :development
69
- version_requirements: *id003
178
+ prerelease: false
179
+ version_requirements: *id011
70
180
  description: A Rails plugin for Japanese mobile-phones
71
181
  email: dara@shidara.net
72
182
  executables: []
@@ -76,7 +186,6 @@ extensions: []
76
186
  extra_rdoc_files:
77
187
  - README.rdoc
78
188
  files:
79
- - .gitignore
80
189
  - .rspec
81
190
  - CHANGELOG
82
191
  - Gemfile
@@ -154,17 +263,22 @@ files:
154
263
  - test/rails/overrides/app/controllers/filter_controller.rb
155
264
  - test/rails/overrides/app/controllers/filter_controller_base.rb
156
265
  - test/rails/overrides/app/controllers/hankaku_filter_controller.rb
266
+ - test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb
157
267
  - test/rails/overrides/app/controllers/links_controller.rb
158
268
  - test/rails/overrides/app/controllers/mobile_spec_controller.rb
159
269
  - test/rails/overrides/app/controllers/template_path_controller.rb
160
270
  - test/rails/overrides/app/controllers/trans_sid_always_and_session_off_controller.rb
161
271
  - test/rails/overrides/app/controllers/trans_sid_always_controller.rb
162
272
  - test/rails/overrides/app/controllers/trans_sid_base_controller.rb
273
+ - test/rails/overrides/app/controllers/trans_sid_metal_controller.rb
163
274
  - test/rails/overrides/app/controllers/trans_sid_mobile_controller.rb
164
275
  - test/rails/overrides/app/controllers/trans_sid_none_controller.rb
165
276
  - test/rails/overrides/app/models/user.rb
166
277
  - test/rails/overrides/app/views/filter/index.html.erb
167
278
  - test/rails/overrides/app/views/hankaku_filter/index.html.erb
279
+ - test/rails/overrides/app/views/hankaku_input_filter/index.html.erb
280
+ - test/rails/overrides/app/views/hankaku_input_filter/index_xhtml.html.erb
281
+ - test/rails/overrides/app/views/layouts/xhtml.html.erb
168
282
  - test/rails/overrides/app/views/links/au_gps.html.erb
169
283
  - test/rails/overrides/app/views/links/au_location.html.erb
170
284
  - test/rails/overrides/app/views/links/docomo_foma_gps.html.erb
@@ -217,8 +331,8 @@ homepage: http://github.com/jpmobile/jpmobile
217
331
  licenses: []
218
332
 
219
333
  post_install_message:
220
- rdoc_options:
221
- - --charset=UTF-8
334
+ rdoc_options: []
335
+
222
336
  require_paths:
223
337
  - lib
224
338
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -245,57 +359,59 @@ signing_key:
245
359
  specification_version: 3
246
360
  summary: A Rails plugin for Japanese mobile-phones
247
361
  test_files:
248
- - spec/rack/jpmobile/emoticon_spec.rb
362
+ - spec/rack/jpmobile/android_spec.rb
249
363
  - spec/rack/jpmobile/au_spec.rb
250
- - spec/rack/jpmobile/willcom_spec.rb
251
- - spec/rack/jpmobile/params_filter_spec.rb
252
364
  - spec/rack/jpmobile/docomo_spec.rb
365
+ - spec/rack/jpmobile/emoticon_spec.rb
253
366
  - spec/rack/jpmobile/filter_spec.rb
254
- - spec/rack/jpmobile/windows_phone.rb
255
- - spec/rack/jpmobile/mobile_by_ua_spec.rb
256
367
  - spec/rack/jpmobile/iphone_spec.rb
368
+ - spec/rack/jpmobile/mobile_by_ua_spec.rb
369
+ - spec/rack/jpmobile/params_filter_spec.rb
257
370
  - spec/rack/jpmobile/softbank_spec.rb
258
- - spec/rack/jpmobile/android_spec.rb
371
+ - spec/rack/jpmobile/willcom_spec.rb
372
+ - spec/rack/jpmobile/windows_phone.rb
373
+ - spec/rack_helper.rb
374
+ - spec/spec_helper.rb
259
375
  - spec/unit/detect_by_email_spec.rb
376
+ - spec/unit/is_carrier_spec.rb
260
377
  - spec/unit/spec_helper.rb
261
- - spec/unit/valid_ip_spec.rb
262
378
  - spec/unit/util_spec.rb
263
- - spec/unit/is_carrier_spec.rb
264
- - spec/spec_helper.rb
265
- - spec/rack_helper.rb
379
+ - spec/unit/valid_ip_spec.rb
266
380
  - test/legacy/emoticon_test.rb
267
381
  - test/legacy/helper.rb
268
- - test/sinatra/guestbook.rb
269
- - test/sinatra/test/filter_test.rb
270
- - test/rails/overrides/spec/helpers/helpers_spec.rb
271
- - test/rails/overrides/spec/requests/softbank_emulator_spec.rb
272
- - test/rails/overrides/spec/requests/docomo_spec.rb
273
- - test/rails/overrides/spec/requests/helpers_spec.rb
274
- - test/rails/overrides/spec/requests/docomo_guid_spec.rb
275
- - test/rails/overrides/spec/requests/trans_sid_spec.rb
276
- - test/rails/overrides/spec/requests/template_path_spec.rb
277
- - test/rails/overrides/spec/requests/filter_spec.rb
278
- - test/rails/overrides/spec/requests/pc_spec.rb
279
- - test/rails/overrides/spec/requests/emobile_spec.rb
280
- - test/rails/overrides/spec/spec_helper.rb
281
- - test/rails/overrides/autotest/discover.rb
282
- - test/rails/overrides/app/models/user.rb
283
- - test/rails/overrides/app/controllers/trans_sid_always_controller.rb
284
- - test/rails/overrides/app/controllers/hankaku_filter_controller.rb
285
- - test/rails/overrides/app/controllers/filter_controller_base.rb
286
- - test/rails/overrides/app/controllers/links_controller.rb
287
- - test/rails/overrides/app/controllers/trans_sid_base_controller.rb
288
- - test/rails/overrides/app/controllers/trans_sid_none_controller.rb
289
- - test/rails/overrides/app/controllers/trans_sid_always_and_session_off_controller.rb
290
- - test/rails/overrides/app/controllers/template_path_controller.rb
382
+ - test/rails/overrides/app/controllers/application_controller.rb
383
+ - test/rails/overrides/app/controllers/docomo_guid_always_controller.rb
384
+ - test/rails/overrides/app/controllers/docomo_guid_base_controller.rb
291
385
  - test/rails/overrides/app/controllers/docomo_guid_docomo_controller.rb
292
386
  - test/rails/overrides/app/controllers/filter_controller.rb
387
+ - test/rails/overrides/app/controllers/filter_controller_base.rb
388
+ - test/rails/overrides/app/controllers/hankaku_filter_controller.rb
389
+ - test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb
390
+ - test/rails/overrides/app/controllers/links_controller.rb
293
391
  - test/rails/overrides/app/controllers/mobile_spec_controller.rb
392
+ - test/rails/overrides/app/controllers/template_path_controller.rb
393
+ - test/rails/overrides/app/controllers/trans_sid_always_and_session_off_controller.rb
394
+ - test/rails/overrides/app/controllers/trans_sid_always_controller.rb
395
+ - test/rails/overrides/app/controllers/trans_sid_base_controller.rb
396
+ - test/rails/overrides/app/controllers/trans_sid_metal_controller.rb
294
397
  - test/rails/overrides/app/controllers/trans_sid_mobile_controller.rb
295
- - test/rails/overrides/app/controllers/application_controller.rb
296
- - test/rails/overrides/app/controllers/docomo_guid_always_controller.rb
297
- - test/rails/overrides/app/controllers/docomo_guid_base_controller.rb
298
- - test/rails/overrides/db/migrate/20100824062306_create_users.rb
299
- - test/rails/overrides/db/migrate/001_add_sessions_table.rb
300
- - test/rails/overrides/config/routes.rb
398
+ - test/rails/overrides/app/controllers/trans_sid_none_controller.rb
399
+ - test/rails/overrides/app/models/user.rb
400
+ - test/rails/overrides/autotest/discover.rb
301
401
  - test/rails/overrides/config/initializers/jpmobile_generator.rb
402
+ - test/rails/overrides/config/routes.rb
403
+ - test/rails/overrides/db/migrate/001_add_sessions_table.rb
404
+ - test/rails/overrides/db/migrate/20100824062306_create_users.rb
405
+ - test/rails/overrides/spec/helpers/helpers_spec.rb
406
+ - test/rails/overrides/spec/requests/docomo_guid_spec.rb
407
+ - test/rails/overrides/spec/requests/docomo_spec.rb
408
+ - test/rails/overrides/spec/requests/emobile_spec.rb
409
+ - test/rails/overrides/spec/requests/filter_spec.rb
410
+ - test/rails/overrides/spec/requests/helpers_spec.rb
411
+ - test/rails/overrides/spec/requests/pc_spec.rb
412
+ - test/rails/overrides/spec/requests/softbank_emulator_spec.rb
413
+ - test/rails/overrides/spec/requests/template_path_spec.rb
414
+ - test/rails/overrides/spec/requests/trans_sid_spec.rb
415
+ - test/rails/overrides/spec/spec_helper.rb
416
+ - test/sinatra/guestbook.rb
417
+ - test/sinatra/test/filter_test.rb
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- doc
2
- tmp
3
- pkg
4
- .bundle
5
- Gemfile
6
- Gemfile.lock
7
- vendor