railroader 4.3.5 → 4.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +16 -0
- data/README.md +15 -0
- data/bin/railroader +1 -1
- data/lib/railroader/call_index.rb +11 -11
- data/lib/railroader/checks/base_check.rb +43 -43
- data/lib/railroader/checks/check_basic_auth.rb +3 -3
- data/lib/railroader/checks/check_content_tag.rb +9 -9
- data/lib/railroader/checks/check_create_with.rb +2 -2
- data/lib/railroader/checks/check_cross_site_scripting.rb +24 -24
- data/lib/railroader/checks/check_default_routes.rb +5 -5
- data/lib/railroader/checks/check_deserialize.rb +1 -1
- data/lib/railroader/checks/check_dynamic_finders.rb +1 -1
- data/lib/railroader/checks/check_escape_function.rb +3 -3
- data/lib/railroader/checks/check_evaluation.rb +4 -4
- data/lib/railroader/checks/check_execute.rb +8 -8
- data/lib/railroader/checks/check_file_access.rb +2 -2
- data/lib/railroader/checks/check_filter_skipping.rb +2 -2
- data/lib/railroader/checks/check_forgery_setting.rb +3 -3
- data/lib/railroader/checks/check_jruby_xml.rb +1 -1
- data/lib/railroader/checks/check_json_parsing.rb +2 -2
- data/lib/railroader/checks/check_link_to.rb +12 -12
- data/lib/railroader/checks/check_link_to_href.rb +9 -9
- data/lib/railroader/checks/check_mail_to.rb +4 -4
- data/lib/railroader/checks/check_mass_assignment.rb +5 -5
- data/lib/railroader/checks/check_model_attributes.rb +6 -6
- data/lib/railroader/checks/check_model_serialize.rb +2 -2
- data/lib/railroader/checks/check_nested_attributes.rb +2 -2
- data/lib/railroader/checks/check_nested_attributes_bypass.rb +1 -1
- data/lib/railroader/checks/check_quote_table_name.rb +3 -3
- data/lib/railroader/checks/check_redirect.rb +19 -19
- data/lib/railroader/checks/check_regex_dos.rb +3 -3
- data/lib/railroader/checks/check_render.rb +4 -4
- data/lib/railroader/checks/check_response_splitting.rb +2 -2
- data/lib/railroader/checks/check_safe_buffer_manipulation.rb +4 -4
- data/lib/railroader/checks/check_sanitize_methods.rb +2 -2
- data/lib/railroader/checks/check_select_tag.rb +4 -4
- data/lib/railroader/checks/check_select_vulnerability.rb +3 -3
- data/lib/railroader/checks/check_send.rb +1 -1
- data/lib/railroader/checks/check_send_file.rb +1 -1
- data/lib/railroader/checks/check_session_settings.rb +10 -10
- data/lib/railroader/checks/check_single_quotes.rb +8 -8
- data/lib/railroader/checks/check_skip_before_filter.rb +5 -5
- data/lib/railroader/checks/check_sql.rb +41 -41
- data/lib/railroader/checks/check_strip_tags.rb +6 -6
- data/lib/railroader/checks/check_symbol_dos_cve.rb +0 -1
- data/lib/railroader/checks/check_translate_bug.rb +4 -4
- data/lib/railroader/checks/check_unsafe_reflection.rb +1 -1
- data/lib/railroader/checks/check_validation_regex.rb +7 -7
- data/lib/railroader/checks/check_weak_hash.rb +1 -1
- data/lib/railroader/checks/check_without_protection.rb +9 -9
- data/lib/railroader/checks/check_yaml_parsing.rb +5 -5
- data/lib/railroader/checks.rb +18 -18
- data/lib/railroader/commandline.rb +1 -1
- data/lib/railroader/differ.rb +2 -2
- data/lib/railroader/options.rb +7 -7
- data/lib/railroader/parsers/rails2_erubis.rb +1 -1
- data/lib/railroader/parsers/rails2_xss_plugin_erubis.rb +4 -4
- data/lib/railroader/parsers/template_parser.rb +1 -1
- data/lib/railroader/processor.rb +17 -17
- data/lib/railroader/processors/alias_processor.rb +72 -72
- data/lib/railroader/processors/base_processor.rb +31 -31
- data/lib/railroader/processors/controller_alias_processor.rb +31 -31
- data/lib/railroader/processors/controller_processor.rb +29 -29
- data/lib/railroader/processors/erb_template_processor.rb +8 -8
- data/lib/railroader/processors/erubis_template_processor.rb +6 -6
- data/lib/railroader/processors/gem_processor.rb +1 -1
- data/lib/railroader/processors/haml_template_processor.rb +14 -14
- data/lib/railroader/processors/lib/call_conversion_helper.rb +1 -1
- data/lib/railroader/processors/lib/find_all_calls.rb +15 -15
- data/lib/railroader/processors/lib/find_call.rb +26 -26
- data/lib/railroader/processors/lib/find_return_value.rb +11 -11
- data/lib/railroader/processors/lib/module_helper.rb +1 -1
- data/lib/railroader/processors/lib/processor_helper.rb +4 -4
- data/lib/railroader/processors/lib/rails2_config_processor.rb +20 -20
- data/lib/railroader/processors/lib/rails2_route_processor.rb +38 -38
- data/lib/railroader/processors/lib/rails3_config_processor.rb +14 -14
- data/lib/railroader/processors/lib/rails3_route_processor.rb +16 -16
- data/lib/railroader/processors/lib/render_helper.rb +32 -32
- data/lib/railroader/processors/lib/route_helper.rb +12 -12
- data/lib/railroader/processors/library_processor.rb +1 -1
- data/lib/railroader/processors/model_processor.rb +9 -9
- data/lib/railroader/processors/output_processor.rb +3 -3
- data/lib/railroader/processors/slim_template_processor.rb +4 -4
- data/lib/railroader/processors/template_alias_processor.rb +10 -10
- data/lib/railroader/processors/template_processor.rb +7 -7
- data/lib/railroader/report/renderer.rb +1 -1
- data/lib/railroader/report/report_base.rb +12 -12
- data/lib/railroader/report/report_csv.rb +2 -2
- data/lib/railroader/report/report_html.rb +5 -5
- data/lib/railroader/report/report_markdown.rb +2 -2
- data/lib/railroader/report/report_table.rb +3 -3
- data/lib/railroader/report/report_tabs.rb +2 -2
- data/lib/railroader/report/report_text.rb +3 -4
- data/lib/railroader/report.rb +3 -3
- data/lib/railroader/rescanner.rb +36 -36
- data/lib/railroader/scanner.rb +23 -23
- data/lib/railroader/tracker/config.rb +3 -3
- data/lib/railroader/tracker/controller.rb +2 -2
- data/lib/railroader/tracker.rb +42 -42
- data/lib/railroader/util.rb +47 -47
- data/lib/railroader/version.rb +1 -1
- data/lib/railroader/warning.rb +9 -10
- data/lib/railroader.rb +32 -32
- data/lib/ruby_parser/bm_sexp.rb +63 -63
- data/lib/ruby_parser/bm_sexp_processor.rb +3 -3
- metadata +4 -4
@@ -3,21 +3,21 @@ require 'railroader/processors/lib/render_helper'
|
|
3
3
|
require 'railroader/processors/lib/render_path'
|
4
4
|
require 'railroader/processors/lib/find_return_value'
|
5
5
|
|
6
|
-
#Processes aliasing in controllers, but includes following
|
7
|
-
#renders in routes and putting variables into templates
|
6
|
+
# Processes aliasing in controllers, but includes following
|
7
|
+
# renders in routes and putting variables into templates
|
8
8
|
class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
9
9
|
include Railroader::RenderHelper
|
10
10
|
|
11
|
-
#If only_method is specified, only that method will be processed,
|
12
|
-
#other methods will be skipped.
|
13
|
-
#This is for rescanning just a single action.
|
11
|
+
# If only_method is specified, only that method will be processed,
|
12
|
+
# other methods will be skipped.
|
13
|
+
# This is for rescanning just a single action.
|
14
14
|
def initialize app_tree, tracker, only_method = nil
|
15
15
|
super tracker
|
16
16
|
@app_tree = app_tree
|
17
17
|
@only_method = only_method
|
18
18
|
@rendered = false
|
19
19
|
@current_class = @current_module = @current_method = nil
|
20
|
-
@method_cache = {} #Cache method lookups
|
20
|
+
@method_cache = {} # Cache method lookups
|
21
21
|
end
|
22
22
|
|
23
23
|
def process_controller name, src, file_name
|
@@ -34,7 +34,7 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
#Process modules mixed into the controller, in case they contain actions.
|
37
|
+
# Process modules mixed into the controller, in case they contain actions.
|
38
38
|
def process_mixins
|
39
39
|
controller = @tracker.controllers[@current_class]
|
40
40
|
|
@@ -43,43 +43,43 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
43
43
|
|
44
44
|
next unless mixin
|
45
45
|
|
46
|
-
#Process methods in alphabetical order for consistency
|
46
|
+
# Process methods in alphabetical order for consistency
|
47
47
|
methods = mixin.methods_public.keys.map { |n| n.to_s }.sort.map { |n| n.to_sym }
|
48
48
|
|
49
49
|
methods.each do |name|
|
50
|
-
#Need to process the method like it was in a controller in order
|
51
|
-
#to get the renders set
|
50
|
+
# Need to process the method like it was in a controller in order
|
51
|
+
# to get the renders set
|
52
52
|
processor = Railroader::ControllerProcessor.new(@app_tree, @tracker)
|
53
53
|
method = mixin.get_method(name)[:src].deep_clone
|
54
54
|
|
55
55
|
if node_type? method, :defn
|
56
56
|
method = processor.process_defn method
|
57
57
|
else
|
58
|
-
#Should be a defn, but this will catch other cases
|
58
|
+
# Should be a defn, but this will catch other cases
|
59
59
|
method = processor.process method
|
60
60
|
end
|
61
61
|
|
62
62
|
@file_name = mixin.file
|
63
|
-
#Then process it like any other method in the controller
|
63
|
+
# Then process it like any other method in the controller
|
64
64
|
process method
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
#Skip it, must be an inner class
|
69
|
+
# Skip it, must be an inner class
|
70
70
|
def process_class exp
|
71
71
|
exp
|
72
72
|
end
|
73
73
|
|
74
|
-
#Processes a method definition, which may include
|
75
|
-
#processing any rendered templates.
|
74
|
+
# Processes a method definition, which may include
|
75
|
+
# processing any rendered templates.
|
76
76
|
def process_defn exp
|
77
77
|
meth_name = exp.method_name
|
78
78
|
|
79
79
|
Railroader.debug "Processing #{@current_class}##{meth_name}"
|
80
80
|
|
81
|
-
#Skip if instructed to only process a specific method
|
82
|
-
#(but don't skip if this method was called from elsewhere)
|
81
|
+
# Skip if instructed to only process a specific method
|
82
|
+
# (but don't skip if this method was called from elsewhere)
|
83
83
|
return exp if @current_method.nil? and @only_method and @only_method != meth_name
|
84
84
|
|
85
85
|
is_route = route? meth_name
|
@@ -105,7 +105,7 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
105
105
|
exp
|
106
106
|
end
|
107
107
|
|
108
|
-
#Look for calls to head()
|
108
|
+
# Look for calls to head()
|
109
109
|
def process_call exp
|
110
110
|
exp = super
|
111
111
|
return exp unless call? exp
|
@@ -125,7 +125,7 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
125
125
|
exp
|
126
126
|
end
|
127
127
|
|
128
|
-
#Check for +respond_to+
|
128
|
+
# Check for +respond_to+
|
129
129
|
def process_iter exp
|
130
130
|
super
|
131
131
|
|
@@ -136,9 +136,9 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
136
136
|
exp
|
137
137
|
end
|
138
138
|
|
139
|
-
#Processes a call to a before filter.
|
140
|
-
#Basically, adds any instance variable assignments to the environment.
|
141
|
-
#TODO: method arguments?
|
139
|
+
# Processes a call to a before filter.
|
140
|
+
# Basically, adds any instance variable assignments to the environment.
|
141
|
+
# TODO: method arguments?
|
142
142
|
def process_before_filter name
|
143
143
|
filter = find_method name, @current_class
|
144
144
|
|
@@ -167,13 +167,13 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
-
#Processes the default template for the current action
|
170
|
+
# Processes the default template for the current action
|
171
171
|
def process_default_render exp
|
172
172
|
process_layout
|
173
173
|
process_template template_name, nil, nil, nil
|
174
174
|
end
|
175
175
|
|
176
|
-
#Process template and add the current class and method name as called_from info
|
176
|
+
# Process template and add the current class and method name as called_from info
|
177
177
|
def process_template name, args, _, line
|
178
178
|
# If line is null, assume implicit render and set the end of the action
|
179
179
|
# method as the line number
|
@@ -191,7 +191,7 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
191
191
|
super name, args, render_path, line
|
192
192
|
end
|
193
193
|
|
194
|
-
#Turns a method name into a template name
|
194
|
+
# Turns a method name into a template name
|
195
195
|
def template_name name = nil
|
196
196
|
name ||= @current_method
|
197
197
|
name = name.to_s
|
@@ -204,7 +204,7 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
207
|
-
#Determines default layout name
|
207
|
+
# Determines default layout name
|
208
208
|
def layout_name
|
209
209
|
controller = @tracker.controllers[@current_class]
|
210
210
|
|
@@ -218,7 +218,7 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
218
218
|
nil
|
219
219
|
end
|
220
220
|
|
221
|
-
#Returns true if the given method name is also a route
|
221
|
+
# Returns true if the given method name is also a route
|
222
222
|
def route? method
|
223
223
|
if @tracker.routes[:allow_all_actions] or @tracker.options[:assume_all_routes]
|
224
224
|
true
|
@@ -228,7 +228,7 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
231
|
-
#Get list of filters, including those that are inherited
|
231
|
+
# Get list of filters, including those that are inherited
|
232
232
|
def before_filter_list method, klass
|
233
233
|
controller = @tracker.controllers[klass]
|
234
234
|
|
@@ -239,11 +239,11 @@ class Railroader::ControllerAliasProcessor < Railroader::AliasProcessor
|
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
242
|
-
#Finds a method in the given class or a parent class
|
242
|
+
# Finds a method in the given class or a parent class
|
243
243
|
#
|
244
|
-
#Returns nil if the method could not be found.
|
244
|
+
# Returns nil if the method could not be found.
|
245
245
|
#
|
246
|
-
#If found, returns hash table with controller name and method sexp.
|
246
|
+
# If found, returns hash table with controller name and method sexp.
|
247
247
|
def find_method method_name, klass
|
248
248
|
return nil if sexp? method_name
|
249
249
|
method_name = method_name.to_sym
|
@@ -2,7 +2,7 @@ require 'railroader/processors/base_processor'
|
|
2
2
|
require 'railroader/processors/lib/module_helper'
|
3
3
|
require 'railroader/tracker/controller'
|
4
4
|
|
5
|
-
#Processes controller. Results are put in tracker.controllers
|
5
|
+
# Processes controller. Results are put in tracker.controllers
|
6
6
|
class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
7
7
|
include Railroader::ModuleHelper
|
8
8
|
|
@@ -19,20 +19,20 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
19
19
|
@concerns = Set.new
|
20
20
|
end
|
21
21
|
|
22
|
-
#Use this method to process a Controller
|
22
|
+
# Use this method to process a Controller
|
23
23
|
def process_controller src, file_name = nil
|
24
24
|
@file_name = file_name
|
25
25
|
process src
|
26
26
|
end
|
27
27
|
|
28
|
-
#s(:class, NAME, PARENT, s(:scope ...))
|
28
|
+
# s(:class, NAME, PARENT, s(:scope ...))
|
29
29
|
def process_class exp
|
30
30
|
name = class_name(exp.class_name)
|
31
31
|
parent = class_name(exp.parent_name)
|
32
32
|
|
33
|
-
#If inside a real controller, treat any other classes as libraries.
|
34
|
-
#But if not inside a controller already, then the class may include
|
35
|
-
#a real controller, so we can't take this shortcut.
|
33
|
+
# If inside a real controller, treat any other classes as libraries.
|
34
|
+
# But if not inside a controller already, then the class may include
|
35
|
+
# a real controller, so we can't take this shortcut.
|
36
36
|
if @current_class and @current_class.name.to_s.end_with? "Controller"
|
37
37
|
Railroader.debug "[Notice] Treating inner class as library: #{name}"
|
38
38
|
Railroader::LibraryProcessor.new(@tracker).process_library exp, @file_name
|
@@ -41,11 +41,11 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
41
41
|
|
42
42
|
if not name.to_s.end_with? "Controller"
|
43
43
|
Railroader.debug "[Notice] Adding noncontroller as library: #{name}"
|
44
|
-
#Set the class to be a module in order to get the right namespacing.
|
45
|
-
#Add class to libraries, in case it is needed later (e.g. it's used
|
46
|
-
#as a parent class for a controller.)
|
47
|
-
#However, still want to process it in this class, so have to set
|
48
|
-
|
44
|
+
# Set the class to be a module in order to get the right namespacing.
|
45
|
+
# Add class to libraries, in case it is needed later (e.g. it's used
|
46
|
+
# as a parent class for a controller.)
|
47
|
+
# However, still want to process it in this class, so have to set
|
48
|
+
# @current_class to this not-really-a-controller thing.
|
49
49
|
process_module exp, parent
|
50
50
|
|
51
51
|
return exp
|
@@ -73,7 +73,7 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
#Look for specific calls inside the controller
|
76
|
+
# Look for specific calls inside the controller
|
77
77
|
def process_call exp
|
78
78
|
return exp if process_call_defn? exp
|
79
79
|
|
@@ -86,17 +86,17 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
86
86
|
first_arg = exp.first_arg
|
87
87
|
last_arg = exp.last_arg
|
88
88
|
|
89
|
-
#Methods called inside class definition
|
90
|
-
#like attr_* and other settings
|
89
|
+
# Methods called inside class definition
|
90
|
+
# like attr_* and other settings
|
91
91
|
if @current_method.nil? and target.nil? and @current_class
|
92
|
-
if first_arg.nil? #No args
|
92
|
+
if first_arg.nil? # No args
|
93
93
|
case method
|
94
94
|
when :private, :protected, :public
|
95
95
|
@visibility = method
|
96
96
|
when :protect_from_forgery
|
97
97
|
@current_class.options[:protect_from_forgery] = true
|
98
98
|
else
|
99
|
-
|
99
|
+
# ??
|
100
100
|
end
|
101
101
|
else
|
102
102
|
case method
|
@@ -122,7 +122,7 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
122
122
|
@current_class.skip_filter exp
|
123
123
|
when :layout
|
124
124
|
if string? last_arg
|
125
|
-
#layout "some_layout"
|
125
|
+
# layout "some_layout"
|
126
126
|
|
127
127
|
name = last_arg.value.to_s
|
128
128
|
if @app_tree.layout_exists?(name)
|
@@ -131,7 +131,7 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
131
131
|
Railroader.debug "[Notice] Layout not found: #{name}"
|
132
132
|
end
|
133
133
|
elsif node_type? last_arg, :nil, :false
|
134
|
-
#layout :false or layout nil
|
134
|
+
# layout :false or layout nil
|
135
135
|
@current_class.layout = false
|
136
136
|
end
|
137
137
|
else
|
@@ -143,10 +143,10 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
143
143
|
elsif target == nil and method == :render
|
144
144
|
make_render exp
|
145
145
|
elsif exp == FORMAT_HTML and context[1] != :iter
|
146
|
-
#This is an empty call to
|
146
|
+
# This is an empty call to
|
147
147
|
# format.html
|
148
|
-
#Which renders the default template if no arguments
|
149
|
-
#Need to make more generic, though.
|
148
|
+
# Which renders the default template if no arguments
|
149
|
+
# Need to make more generic, though.
|
150
150
|
call = Sexp.new :render, :default, @current_method
|
151
151
|
call.line(exp.line)
|
152
152
|
call
|
@@ -157,12 +157,12 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
-
#Look for before_filters and add fake ones if necessary
|
160
|
+
# Look for before_filters and add fake ones if necessary
|
161
161
|
def process_iter exp
|
162
162
|
if @current_method.nil? and call? exp.block_call
|
163
163
|
block_call_name = exp.block_call.method
|
164
164
|
|
165
|
-
if block_call_name == :before_filter
|
165
|
+
if block_call_name == :before_filter or block_call_name == :before_action
|
166
166
|
add_fake_filter exp
|
167
167
|
else
|
168
168
|
super
|
@@ -172,22 +172,22 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
|
-
#Sets default layout for renders inside Controller
|
175
|
+
# Sets default layout for renders inside Controller
|
176
176
|
def set_layout_name
|
177
177
|
return if @current_class.layout
|
178
178
|
|
179
179
|
name = underscore(@current_class.name.to_s.split("::")[-1].gsub("Controller", ''))
|
180
180
|
|
181
|
-
#There is a layout for this Controller
|
181
|
+
# There is a layout for this Controller
|
182
182
|
if @app_tree.layout_exists?(name)
|
183
183
|
@current_class.layout = "layouts/#{name}"
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
#This is to handle before_filter do |controller| ... end
|
187
|
+
# This is to handle before_filter do |controller| ... end
|
188
188
|
#
|
189
|
-
#We build a new method and process that the same way as usual
|
190
|
-
#methods and filters.
|
189
|
+
# We build a new method and process that the same way as usual
|
190
|
+
# methods and filters.
|
191
191
|
def add_fake_filter exp
|
192
192
|
unless @current_class
|
193
193
|
Railroader.debug "Skipping before_filter outside controller: #{exp}"
|
@@ -211,7 +211,7 @@ class Railroader::ControllerProcessor < Railroader::BaseProcessor
|
|
211
211
|
block_inner = [exp.block]
|
212
212
|
end
|
213
213
|
|
214
|
-
#Build Sexp for filter method
|
214
|
+
# Build Sexp for filter method
|
215
215
|
body = Sexp.new(:lasgn,
|
216
216
|
block_variable,
|
217
217
|
Sexp.new(:call, Sexp.new(:const, @current_class.name), :new))
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'railroader/processors/template_processor'
|
2
2
|
|
3
|
-
#Processes ERB templates
|
4
|
-
#(those ending in .html.erb or .rthml).
|
3
|
+
# Processes ERB templates
|
4
|
+
# (those ending in .html.erb or .rthml).
|
5
5
|
class Railroader::ErbTemplateProcessor < Railroader::TemplateProcessor
|
6
|
-
|
7
|
-
#s(:call, TARGET, :method, ARGS)
|
6
|
+
|
7
|
+
# s(:call, TARGET, :method, ARGS)
|
8
8
|
def process_call exp
|
9
9
|
target = exp.target
|
10
10
|
if sexp? target
|
11
11
|
target = process target
|
12
12
|
end
|
13
13
|
method = exp.method
|
14
|
-
|
15
|
-
#_erbout is the default output variable for erb
|
14
|
+
|
15
|
+
# _erbout is the default output variable for erb
|
16
16
|
if node_type? target, :lvar and target.value == :_erbout
|
17
17
|
if method == :concat or method == :<<
|
18
18
|
@inside_concat = true
|
@@ -25,7 +25,7 @@ class Railroader::ErbTemplateProcessor < Railroader::TemplateProcessor
|
|
25
25
|
|
26
26
|
arg = normalize_output(exp.first_arg)
|
27
27
|
|
28
|
-
if arg.node_type == :str #ignore plain strings
|
28
|
+
if arg.node_type == :str # ignore plain strings
|
29
29
|
ignore
|
30
30
|
else
|
31
31
|
add_output arg
|
@@ -45,7 +45,7 @@ class Railroader::ErbTemplateProcessor < Railroader::TemplateProcessor
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
#Process block, removing irrelevant expressions
|
48
|
+
# Process block, removing irrelevant expressions
|
49
49
|
def process_block exp
|
50
50
|
exp = exp.dup
|
51
51
|
exp.shift
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'railroader/processors/template_processor'
|
2
2
|
|
3
|
-
#Processes ERB templates using Erubis instead of erb.
|
3
|
+
# Processes ERB templates using Erubis instead of erb.
|
4
4
|
class Railroader::ErubisTemplateProcessor < Railroader::TemplateProcessor
|
5
5
|
|
6
|
-
#s(:call, TARGET, :method, ARGS)
|
6
|
+
# s(:call, TARGET, :method, ARGS)
|
7
7
|
def process_call exp
|
8
8
|
target = exp.target
|
9
9
|
if sexp? target
|
@@ -14,13 +14,13 @@ class Railroader::ErubisTemplateProcessor < Railroader::TemplateProcessor
|
|
14
14
|
exp.arglist = process exp.arglist
|
15
15
|
method = exp.method
|
16
16
|
|
17
|
-
#_buf is the default output variable for Erubis
|
17
|
+
# _buf is the default output variable for Erubis
|
18
18
|
if node_type?(target, :lvar, :ivar) and (target.value == :_buf or target.value == :@output_buffer)
|
19
19
|
if method == :<< or method == :safe_concat
|
20
20
|
|
21
21
|
arg = normalize_output(exp.first_arg)
|
22
22
|
|
23
|
-
if arg.node_type == :str #ignore plain strings
|
23
|
+
if arg.node_type == :str # ignore plain strings
|
24
24
|
ignore
|
25
25
|
elsif node_type? target, :ivar and target.value == :@output_buffer
|
26
26
|
add_escaped_output arg
|
@@ -39,7 +39,7 @@ class Railroader::ErubisTemplateProcessor < Railroader::TemplateProcessor
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
#Process blocks, ignoring :ignore exps
|
42
|
+
# Process blocks, ignoring :ignore exps
|
43
43
|
def process_block exp
|
44
44
|
exp = exp.dup
|
45
45
|
exp.shift
|
@@ -56,7 +56,7 @@ class Railroader::ErubisTemplateProcessor < Railroader::TemplateProcessor
|
|
56
56
|
block
|
57
57
|
end
|
58
58
|
|
59
|
-
#Look for assignments to output buffer that look like this:
|
59
|
+
# Look for assignments to output buffer that look like this:
|
60
60
|
# @output_buffer.append = some_output
|
61
61
|
# @output_buffer.safe_append = some_output
|
62
62
|
# @output_buffer.safe_expr_append = some_output
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'railroader/processors/template_processor'
|
2
2
|
|
3
|
-
#Processes HAML templates.
|
3
|
+
# Processes HAML templates.
|
4
4
|
class Railroader::HamlTemplateProcessor < Railroader::TemplateProcessor
|
5
5
|
HAML_FORMAT_METHOD = /format_script_(true|false)_(true|false)_(true|false)_(true|false)_(true|false)_(true|false)_(true|false)/
|
6
6
|
HAML_HELPERS = s(:colon2, s(:const, :Haml), :Helpers)
|
7
7
|
JAVASCRIPT_FILTER = s(:colon2, s(:colon2, s(:const, :Haml), :Filters), :Javascript)
|
8
8
|
COFFEE_FILTER = s(:colon2, s(:colon2, s(:const, :Haml), :Filters), :Coffee)
|
9
9
|
|
10
|
-
#Processes call, looking for template output
|
10
|
+
# Processes call, looking for template output
|
11
11
|
def process_call exp
|
12
12
|
target = exp.target
|
13
13
|
if sexp? target
|
@@ -18,7 +18,7 @@ class Railroader::HamlTemplateProcessor < Railroader::TemplateProcessor
|
|
18
18
|
|
19
19
|
if (call? target and target.method == :_hamlout)
|
20
20
|
res = case method
|
21
|
-
when :adjust_tabs, :rstrip!, :attributes #Check attributes, maybe?
|
21
|
+
when :adjust_tabs, :rstrip!, :attributes # Check attributes, maybe?
|
22
22
|
ignore
|
23
23
|
when :options, :buffer
|
24
24
|
exp
|
@@ -69,22 +69,22 @@ class Railroader::HamlTemplateProcessor < Railroader::TemplateProcessor
|
|
69
69
|
res.line(exp.line)
|
70
70
|
res
|
71
71
|
|
72
|
-
#_hamlout.buffer <<
|
73
|
-
#This seems to be used rarely, but directly appends args to output buffer.
|
74
|
-
#Has something to do with values of blocks?
|
72
|
+
# _hamlout.buffer <<
|
73
|
+
# This seems to be used rarely, but directly appends args to output buffer.
|
74
|
+
# Has something to do with values of blocks?
|
75
75
|
elsif sexp? target and method == :<< and is_buffer_target? target
|
76
76
|
@inside_concat = true
|
77
77
|
exp.first_arg = process(exp.first_arg)
|
78
78
|
out = normalize_output(exp.first_arg)
|
79
79
|
@inside_concat = false
|
80
80
|
|
81
|
-
if out.node_type == :str #ignore plain strings
|
81
|
+
if out.node_type == :str # ignore plain strings
|
82
82
|
ignore
|
83
83
|
else
|
84
84
|
add_output out
|
85
85
|
end
|
86
86
|
elsif target == nil and method == :render
|
87
|
-
#Process call to render()
|
87
|
+
# Process call to render()
|
88
88
|
exp.arglist = process exp.arglist
|
89
89
|
make_render_in_view exp
|
90
90
|
elsif target == nil and method == :find_and_preserve and exp.first_arg
|
@@ -102,7 +102,7 @@ class Railroader::HamlTemplateProcessor < Railroader::TemplateProcessor
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
#If inside an output stream, only return the final expression
|
105
|
+
# If inside an output stream, only return the final expression
|
106
106
|
def process_block exp
|
107
107
|
exp = exp.dup
|
108
108
|
exp.shift
|
@@ -126,8 +126,8 @@ class Railroader::HamlTemplateProcessor < Railroader::TemplateProcessor
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
#Checks if the buffer is the target in a method call Sexp.
|
130
|
-
#TODO: Test this
|
129
|
+
# Checks if the buffer is the target in a method call Sexp.
|
130
|
+
# TODO: Test this
|
131
131
|
def is_buffer_target? exp
|
132
132
|
exp.node_type == :call and
|
133
133
|
node_type? exp.target, :lvar and
|
@@ -135,8 +135,8 @@ class Railroader::HamlTemplateProcessor < Railroader::TemplateProcessor
|
|
135
135
|
exp.method == :buffer
|
136
136
|
end
|
137
137
|
|
138
|
-
#HAML likes to put interpolated values into _hamlout.push_text
|
139
|
-
#but we want to handle those individually
|
138
|
+
# HAML likes to put interpolated values into _hamlout.push_text
|
139
|
+
# but we want to handle those individually
|
140
140
|
def build_output_from_push_text exp, default = :output
|
141
141
|
if string_interp? exp
|
142
142
|
exp.map! do |e|
|
@@ -153,7 +153,7 @@ class Railroader::HamlTemplateProcessor < Railroader::TemplateProcessor
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
#Gets outputs from values interpolated into _hamlout.push_text
|
156
|
+
# Gets outputs from values interpolated into _hamlout.push_text
|
157
157
|
def get_pushed_value exp, default = :output
|
158
158
|
return exp unless sexp? exp
|
159
159
|
|
@@ -68,7 +68,7 @@ module Railroader
|
|
68
68
|
if args.length == 1 and integer? args.first
|
69
69
|
index = args.first.value
|
70
70
|
|
71
|
-
#Have to do this because first element is :array and we have to skip it
|
71
|
+
# Have to do this because first element is :array and we have to skip it
|
72
72
|
array[1..-1][index] or original_exp
|
73
73
|
else
|
74
74
|
original_exp
|
@@ -12,8 +12,8 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
12
12
|
@cache = {}
|
13
13
|
end
|
14
14
|
|
15
|
-
#Process the given source. Provide either class and method being searched
|
16
|
-
#or the template. These names are used when reporting results.
|
15
|
+
# Process the given source. Provide either class and method being searched
|
16
|
+
# or the template. These names are used when reporting results.
|
17
17
|
def process_source exp, opts
|
18
18
|
@current_class = opts[:class]
|
19
19
|
@current_method = opts[:method]
|
@@ -23,7 +23,7 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
23
23
|
process exp
|
24
24
|
end
|
25
25
|
|
26
|
-
#Process body of method
|
26
|
+
# Process body of method
|
27
27
|
def process_defn exp
|
28
28
|
return exp unless @current_method
|
29
29
|
process_all exp.body
|
@@ -31,7 +31,7 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
31
31
|
|
32
32
|
alias process_defs process_defn
|
33
33
|
|
34
|
-
#Process body of block
|
34
|
+
# Process body of block
|
35
35
|
def process_rlist exp
|
36
36
|
process_all exp
|
37
37
|
end
|
@@ -54,7 +54,7 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
54
54
|
|
55
55
|
process exp.block
|
56
56
|
else
|
57
|
-
#Probably a :render call with block
|
57
|
+
# Probably a :render call with block
|
58
58
|
process call
|
59
59
|
process exp.block
|
60
60
|
end
|
@@ -62,8 +62,8 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
62
62
|
exp
|
63
63
|
end
|
64
64
|
|
65
|
-
#Calls to render() are converted to s(:render, ...) but we would
|
66
|
-
#like them in the call cache still for speed
|
65
|
+
# Calls to render() are converted to s(:render, ...) but we would
|
66
|
+
# like them in the call cache still for speed
|
67
67
|
def process_render exp
|
68
68
|
process exp.last if sexp? exp.last
|
69
69
|
|
@@ -72,8 +72,8 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
72
72
|
exp
|
73
73
|
end
|
74
74
|
|
75
|
-
#Technically, `` is call to Kernel#`
|
76
|
-
#But we just need them in the call cache for speed
|
75
|
+
# Technically, `` is call to Kernel#`
|
76
|
+
# But we just need them in the call cache for speed
|
77
77
|
def process_dxstr exp
|
78
78
|
process exp.last if sexp? exp.last
|
79
79
|
|
@@ -100,7 +100,7 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
100
100
|
exp
|
101
101
|
end
|
102
102
|
|
103
|
-
#Process an assignment like a call
|
103
|
+
# Process an assignment like a call
|
104
104
|
def process_attrasgn exp
|
105
105
|
process_call exp
|
106
106
|
end
|
@@ -116,8 +116,8 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
116
116
|
:parent => @current_call }
|
117
117
|
end
|
118
118
|
|
119
|
-
#Gets the target of a call as a Symbol
|
120
|
-
#if possible
|
119
|
+
# Gets the target of a call as a Symbol
|
120
|
+
# if possible
|
121
121
|
def get_target exp, include_calls = false
|
122
122
|
if sexp? exp
|
123
123
|
case exp.node_type
|
@@ -154,8 +154,8 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
#Returns method chain as an array
|
158
|
-
#For example, User.human.alive.all would return [:User, :human, :alive, :all]
|
157
|
+
# Returns method chain as an array
|
158
|
+
# For example, User.human.alive.all would return [:User, :human, :alive, :all]
|
159
159
|
def get_chain call
|
160
160
|
if node_type? call, :call, :attrasgn, :safe_call, :safe_attrasgn
|
161
161
|
get_chain(call.target) + [call.method]
|
@@ -187,7 +187,7 @@ class Railroader::FindAllCalls < Railroader::BasicProcessor
|
|
187
187
|
|
188
188
|
end
|
189
189
|
|
190
|
-
#Return info hash for a call Sexp
|
190
|
+
# Return info hash for a call Sexp
|
191
191
|
def create_call_hash exp
|
192
192
|
target = get_target exp.target
|
193
193
|
|