Class: Brakeman::Rails3RoutesProcessor
Overview
Processes the Sexp from routes.rb. Stores results in tracker.routes.
Note that it is only interested in determining what methods on which controllers are used as routes, not the generated URLs for routes.
Constant Summary
BaseProcessor::IGNORE
Constants included
from Util
Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP
SexpProcessor::VERSION
Instance Attribute Summary collapse
#context, #env, #expected
Instance Method Summary
collapse
#add_resource_routes, #add_resources_routes, #add_route, #current_controller=, #prefix
#find_render_type, #ignore, #make_render, #make_render_in_view, #process_arglist, #process_attrasgn, #process_block, #process_class, #process_default, #process_dstr, #process_evstr, #process_hash, #process_if, #process_ignore, #process_lasgn, #process_scope
Methods included from Util
#array?, #block?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #make_call, #node_type?, #number?, #params?, #pluralize, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #true?, #truncate_table, #underscore
#class_name, #process_all, #process_all!, #process_call_args, #process_module
#error_handler, #in_context, #process, #process_dummy, #scope
Constructor Details
Returns a new instance of Rails3RoutesProcessor.
10
11
12
13
14
15
16
17
18
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 10
def initialize tracker
super
@map = Sexp.new(:lvar, :map)
@nested = nil @prefix = [] @current_controller = nil
@with_options = nil @controller_block = false
end
|
Instance Attribute Details
#current_controller ⇒ Object
Returns the value of attribute current_controller.
8
9
10
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 8
def current_controller
@current_controller
end
|
Returns the value of attribute map.
8
9
10
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 8
def map
@map
end
|
Returns the value of attribute nested.
8
9
10
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 8
def nested
@nested
end
|
Instance Method Details
#add_route_from_string(value) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 143
def add_route_from_string value
value = value[1] if string? value
controller, action = value
if action
add_route action, controller
elsif in_controller_block?
add_route value
end
end
|
271
272
273
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 271
def str
str.split "#"
end
|
#in_controller_block ⇒ Object
279
280
281
282
283
284
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 279
def in_controller_block
prev_block = @controller_block
@controller_block = true
yield
@controller_block = prev_block
end
|
#in_controller_block? ⇒ Boolean
275
276
277
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 275
def in_controller_block?
@controller_block
end
|
#process_call(exp) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 24
def process_call exp
case exp.method
when :resources
process_resources exp
when :resource
process_resource exp
when :root
process_root exp
when :member
process_default exp
when :get, :put, :post, :delete
process_verb exp
when :match
process_match exp
else
exp
end
end
|
#process_controller_block(exp) ⇒ Object
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 257
def process_controller_block exp
if string? exp or symbol? exp
self.current_controller = exp.block_call.first_arg.value
in_controller_block do
process exp[-1] if exp[-1]
end
@current_controller = nil
end
exp
end
|
#process_iter(exp) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 43
def process_iter exp
case exp.block_call.method
when :namespace
process_namespace exp
when :resource
process_resource_block exp
when :resources
process_resources_block exp
when :scope
process_scope_block exp
when :controller
process_controller_block exp
else
super
end
end
|
#process_match(exp) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 84
def process_match exp
first_arg = exp.first_arg
second_arg = exp.second_arg
last_arg = exp.last_arg
action_variable = false
if string? first_arg
matcher = first_arg.value
if matcher == ':controller(/:action(/:id(.:format)))' or
matcher.include? ':controller' and matcher.include? ':action' @tracker.routes[:allow_all_actions] = first_arg
return exp
elsif matcher.include? ':action'
action_variable = true
elsif second_arg.nil? and in_controller_block? and not matcher.include? ":"
add_route matcher
end
end
if hash? last_arg
hash_iterate last_arg do |k, v|
if string? k
if string? v
add_route_from_string v
elsif in_controller_block? and symbol? v
add_route v
end
elsif symbol? k
case k.value
when :action
if string? v
add_route_from_string v
else
add_route v
end
action_variable = false
when :to
if string? v
add_route_from_string v[1]
elsif in_controller_block? and symbol? v
add_route v
end
end
end
end
end
if action_variable
@tracker.routes[@current_controller] = :allow_all_actions
end
@current_controller = nil unless in_controller_block?
exp
end
|
#process_namespace(exp) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 60
def process_namespace exp
name = exp.block_call.first_arg.value
block = exp.block
@prefix << camelize(name)
process block
@prefix.pop
exp
end
|
#process_resource(exp) ⇒ Object
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 215
def process_resource exp
exp.each_arg do |s|
if symbol? s
self.current_controller = pluralize(s.value.to_s)
add_resource_routes
else
end
end
@current_controller = nil unless in_controller_block?
exp
end
|
#process_resource_block(exp) ⇒ Object
241
242
243
244
245
246
247
248
249
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 241
def process_resource_block exp
in_controller_block do
process_resource exp.block_call
process exp.block
end
@current_controller = nil
exp
end
|
#process_resources(exp) ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 196
def process_resources exp
first_arg = exp.first_arg
second_arg = exp.second_arg
if second_arg and second_arg.node_type == :hash
self.current_controller = first_arg.value
add_resources_routes
elsif exp.args.all? { |s| symbol? s }
exp.each_arg do |s|
self.current_controller = s.value
add_resources_routes
end
end
@current_controller = nil unless in_controller_block?
exp
end
|
#process_resources_block(exp) ⇒ Object
231
232
233
234
235
236
237
238
239
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 231
def process_resources_block exp
in_controller_block do
process_resources exp.block_call
process exp.block
end
@current_controller = nil
exp
end
|
#process_root(exp) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 74
def process_root exp
if value = hash_access(exp.first_arg, :to)
if string? value
add_route_from_string value
end
end
exp
end
|
#process_routes(exp) ⇒ Object
20
21
22
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 20
def process_routes exp
process exp.dup
end
|
#process_scope_block(exp) ⇒ Object
251
252
253
254
255
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 251
def process_scope_block exp
process exp.block
exp
end
|
#process_verb(exp) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/brakeman/processors/lib/rails3_route_processor.rb', line 155
def process_verb exp
first_arg = exp.first_arg
second_arg = exp.second_arg
if symbol? first_arg and not hash? second_arg
add_route first_arg
elsif hash? second_arg
hash_iterate second_arg do |k, v|
if symbol? k and k.value == :to
if string? v
add_route_from_string v
elsif in_controller_block? and symbol? v
add_route v
end
end
end
elsif string? first_arg
route = first_arg.value.split "/"
if route.length != 2
add_route route[0]
else
add_route route[1], route[0]
end
elsif in_controller_block? and symbol? first_arg
add_route first_arg
else hash? first_arg
hash_iterate first_arg do |k, v|
if string? k
if string? v
add_route_from_string v
elsif in_controller_block?
add_route v
end
end
end
end
@current_controller = nil unless in_controller_block?
exp
end
|