Permalink
Browse files

SoftBankで発生する問題に対応

  • Loading branch information...
1 parent b81f2b5 commit 77a43e42927f529bf3c6dbdf634aa1f40dde1277 @bananagi bananagi committed Jun 6, 2011
Showing with 22 additions and 22 deletions.
  1. +22 −22 lib/opensocial-wap/rack/opensocial_oauth.rb
@@ -25,7 +25,7 @@ def call(env)
status, header, response = @app.call(env)
- response = remove_utf8_form_input_tag(header, response)
+ response = remove_utf8_form_input_tag_from_response(header, response)
new_response = ::Rack::Response.new(response, status, header)
new_response.finish
end
@@ -51,39 +51,39 @@ def verify(env)
request.env['opensocial-wap.helper'] = helper
verified
end
-
- def response_to_body(response)
- if response.respond_to?(:to_str)
- response.to_str
- elsif response.respond_to?(:each)
- body = []
- response.each do |part|
- body << response_to_body(part)
- end
- body.join("\n")
- else
- body
- end
- end
-
- def remove_utf8_form_input_tag(env, response)
+
+ def remove_utf8_form_input_tag_from_response(env, response)
unless response.respond_to?(:body=)
return response
end
if env['Content-Type'] =~ %r!text/html|application/xhtml\+xml!
type, charset = env['Content-Type'].split(/;\s*charset=/)
- body = response_to_body(response)
- if body.encoding == Encoding::UTF_8
- body = body.gsub(/<input name="utf8" type="hidden" value="#{[0x2713].pack("U")}"[^>]*?>/, ' ')
- body = body.gsub(/<input name="utf8" type="hidden" value="&#x2713;"[^>]*?>/, ' ')
-
+ if response.respond_to?(:to_str)
+ response.body = remove_utf8_form_input_tag(response.to_str)
+ elsif response.respond_to?(:each)
+ body = []
+ response.each do |part|
+ body << remove_utf8_form_input_tag(part)
+ end
response.body = body
+ else
+ response.body = remove_utf8_form_input_tag(response.body)
end
end
response
end
+ def remove_utf8_form_input_tag(str)
+ if str.encoding == Encoding::UTF_8
+ str
+ .gsub(/<input name="utf8" type="hidden" value="#{[0x2713].pack("U")}"[^>]*?>/, ' ')
+ .gsub(/<input name="utf8" type="hidden" value="&#x2713;"[^>]*?>/, ' ')
+ else
+ str
+ end
+ end
+
def unauthorized
[ 401,
{ 'Content-Type' => 'text/plain',

0 comments on commit 77a43e4

Please sign in to comment.