Skip to content

Commit c1ebffd

Browse files
committed
🐛 Fix request proxy Class constant reference scopes
- Some classes are reproduced within this gem as nested proxies of the same name, so class lookups could get confused Signed-off-by: Peter Boling <peter.boling@gmail.com>
1 parent 0b3a474 commit c1ebffd

11 files changed

+479
-429
lines changed
Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require "active_support"
24
require "active_support/version"
35
require "action_controller"
@@ -25,61 +27,63 @@
2527
require "action_dispatch/http/request"
2628
end
2729

28-
module OAuth::RequestProxy
29-
class ActionControllerRequest < OAuth::RequestProxy::Base
30-
proxies(defined?(ActionDispatch::AbstractRequest) ? ActionDispatch::AbstractRequest : ActionDispatch::Request)
30+
module OAuth
31+
module RequestProxy
32+
class ActionControllerRequest < OAuth::RequestProxy::Base
33+
proxies(defined?(::ActionDispatch::AbstractRequest) ? ::ActionDispatch::AbstractRequest : ::ActionDispatch::Request)
3134

32-
def method
33-
request.method.to_s.upcase
34-
end
35+
def method
36+
request.method.to_s.upcase
37+
end
3538

36-
def uri
37-
request.url
38-
end
39+
def uri
40+
request.url
41+
end
3942

40-
def parameters
41-
if options[:clobber_request]
42-
options[:parameters] || {}
43-
else
44-
params = request_params.merge(query_params).merge(header_params)
45-
params.stringify_keys! if params.respond_to?(:stringify_keys!)
46-
params.merge(options[:parameters] || {})
43+
def parameters
44+
if options[:clobber_request]
45+
options[:parameters] || {}
46+
else
47+
params = request_params.merge(query_params).merge(header_params)
48+
params.stringify_keys! if params.respond_to?(:stringify_keys!)
49+
params.merge(options[:parameters] || {})
50+
end
4751
end
48-
end
4952

50-
# Override from OAuth::RequestProxy::Base to avoid roundtrip
51-
# conversion to Hash or Array and thus preserve the original
52-
# parameter names
53-
def parameters_for_signature
54-
params = []
55-
params << options[:parameters].to_query if options[:parameters]
53+
# Override from OAuth::RequestProxy::Base to avoid roundtrip
54+
# conversion to Hash or Array and thus preserve the original
55+
# parameter names
56+
def parameters_for_signature
57+
params = []
58+
params << options[:parameters].to_query if options[:parameters]
5659

57-
unless options[:clobber_request]
58-
params << header_params.to_query
59-
params << request.query_string unless query_string_blank?
60+
unless options[:clobber_request]
61+
params << header_params.to_query
62+
params << request.query_string unless query_string_blank?
6063

61-
params << request.raw_post if raw_post_signature?
62-
end
64+
params << request.raw_post if raw_post_signature?
65+
end
6366

64-
params.
65-
join("&").split("&").
66-
reject { |s| s.match(/\A\s*\z/) }.
67-
map { |p| p.split("=").map { |esc| CGI.unescape(esc) } }.
68-
reject { |kv| kv[0] == "oauth_signature" }
69-
end
67+
params.
68+
join("&").split("&").
69+
reject { |s| s.match(/\A\s*\z/) }.
70+
map { |p| p.split("=").map { |esc| CGI.unescape(esc) } }.
71+
reject { |kv| kv[0] == "oauth_signature" }
72+
end
7073

71-
def raw_post_signature?
72-
(request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
73-
end
74+
def raw_post_signature?
75+
(request.post? || request.put?) && request.content_type.to_s.downcase.start_with?("application/x-www-form-urlencoded")
76+
end
7477

75-
protected
78+
protected
7679

77-
def query_params
78-
request.query_parameters
79-
end
80+
def query_params
81+
request.query_parameters
82+
end
8083

81-
def request_params
82-
request.request_parameters
84+
def request_params
85+
request.request_parameters
86+
end
8387
end
8488
end
8589
end
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
# frozen_string_literal: true
2+
13
require "oauth/request_proxy/rack_request"
24

3-
module OAuth::RequestProxy
4-
class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
5-
proxies ActionDispatch::Request
5+
module OAuth
6+
module RequestProxy
7+
class ActionDispatchRequest < OAuth::RequestProxy::RackRequest
8+
proxies ::ActionDispatch::Request
9+
end
610
end
711
end

0 commit comments

Comments
 (0)