railroader 4.3.5 → 4.3.7
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.
- 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
data/lib/railroader.rb
CHANGED
@@ -3,21 +3,21 @@ require 'railroader/version'
|
|
3
3
|
|
4
4
|
module Railroader
|
5
5
|
|
6
|
-
#This exit code is used when warnings are found and the --exit-on-warn
|
7
|
-
#option is set
|
6
|
+
# This exit code is used when warnings are found and the --exit-on-warn
|
7
|
+
# option is set
|
8
8
|
Warnings_Found_Exit_Code = 3
|
9
9
|
|
10
|
-
#Exit code returned when no Rails application is detected
|
10
|
+
# Exit code returned when no Rails application is detected
|
11
11
|
No_App_Found_Exit_Code = 4
|
12
12
|
|
13
|
-
#Exit code returned when railroader was outdated
|
13
|
+
# Exit code returned when railroader was outdated
|
14
14
|
Not_Latest_Version_Exit_Code = 5
|
15
15
|
|
16
|
-
#Exit code returned when user requests non-existent checks
|
16
|
+
# Exit code returned when user requests non-existent checks
|
17
17
|
Missing_Checks_Exit_Code = 6
|
18
18
|
|
19
|
-
#Exit code returned when errors were found and the --exit-on-error
|
20
|
-
#option is set
|
19
|
+
# Exit code returned when errors were found and the --exit-on-error
|
20
|
+
# option is set
|
21
21
|
Errors_Found_Exit_Code = 7
|
22
22
|
|
23
23
|
@debug = false
|
@@ -25,9 +25,9 @@ module Railroader
|
|
25
25
|
@loaded_dependencies = []
|
26
26
|
@vendored_paths = false
|
27
27
|
|
28
|
-
#Run Railroader scan. Returns Tracker object.
|
28
|
+
# Run Railroader scan. Returns Tracker object.
|
29
29
|
#
|
30
|
-
#Options:
|
30
|
+
# Options:
|
31
31
|
#
|
32
32
|
# * :app_path - path to root of Rails app (required)
|
33
33
|
# * :additional_checks_path - array of additional directories containing additional out-of-tree checks to run
|
@@ -63,7 +63,7 @@ module Railroader
|
|
63
63
|
# * :absolute_paths - show absolute path of each file (default: false)
|
64
64
|
# * :summary_only - only output summary section of report for plain/table (:summary_only, :no_summary, true)
|
65
65
|
#
|
66
|
-
#Alternatively, just supply a path as a string.
|
66
|
+
# Alternatively, just supply a path as a string.
|
67
67
|
def self.run options
|
68
68
|
options = set_options options
|
69
69
|
|
@@ -77,7 +77,7 @@ module Railroader
|
|
77
77
|
scan options
|
78
78
|
end
|
79
79
|
|
80
|
-
#Sets up options for run, checks given application path
|
80
|
+
# Sets up options for run, checks given application path
|
81
81
|
def self.set_options options
|
82
82
|
if options.is_a? String
|
83
83
|
options = { :app_path => options }
|
@@ -107,13 +107,13 @@ module Railroader
|
|
107
107
|
options
|
108
108
|
end
|
109
109
|
|
110
|
-
#Load options from YAML file
|
110
|
+
# Load options from YAML file
|
111
111
|
def self.load_options line_options
|
112
112
|
custom_location = line_options[:config_file]
|
113
113
|
quiet = line_options[:quiet]
|
114
114
|
app_path = line_options[:app_path]
|
115
115
|
|
116
|
-
#Load configuration file
|
116
|
+
# Load configuration file
|
117
117
|
if config = config_file(custom_location, app_path)
|
118
118
|
require 'date' # https://github.com/dtao/safe_yaml/issues/80
|
119
119
|
self.load_railroader_dependency 'safe_yaml/load'
|
@@ -156,7 +156,7 @@ module Railroader
|
|
156
156
|
supported_locations.detect {|f| File.file?(f) }
|
157
157
|
end
|
158
158
|
|
159
|
-
#Default set of options
|
159
|
+
# Default set of options
|
160
160
|
def self.default_options
|
161
161
|
{ :assume_all_routes => true,
|
162
162
|
:check_arguments => true,
|
@@ -183,10 +183,10 @@ module Railroader
|
|
183
183
|
}
|
184
184
|
end
|
185
185
|
|
186
|
-
#Determine output formats based on options[:output_formats]
|
187
|
-
#or options[:output_files]
|
186
|
+
# Determine output formats based on options[:output_formats]
|
187
|
+
# or options[:output_files]
|
188
188
|
def self.get_output_formats options
|
189
|
-
#Set output format
|
189
|
+
# Set output format
|
190
190
|
if options[:output_format] && options[:output_files] && options[:output_files].size > 1
|
191
191
|
raise ArgumentError, "Cannot specify output format if multiple output files specified"
|
192
192
|
end
|
@@ -220,7 +220,7 @@ module Railroader
|
|
220
220
|
[:to_markdown]
|
221
221
|
when :cc, :to_cc, :codeclimate, :to_codeclimate
|
222
222
|
[:to_codeclimate]
|
223
|
-
when :plain
|
223
|
+
when :plain, :to_plain, :text, :to_text, :to_s
|
224
224
|
[:to_text]
|
225
225
|
when :table, :to_table
|
226
226
|
[:to_table]
|
@@ -274,7 +274,7 @@ module Railroader
|
|
274
274
|
end
|
275
275
|
private_class_method :get_github_url
|
276
276
|
|
277
|
-
#Output list of checks (for `-k` option)
|
277
|
+
# Output list of checks (for `-k` option)
|
278
278
|
def self.list_checks options
|
279
279
|
require 'railroader/scanner'
|
280
280
|
|
@@ -296,7 +296,7 @@ module Railroader
|
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
299
|
-
#Output configuration to YAML
|
299
|
+
# Output configuration to YAML
|
300
300
|
def self.dump_config options
|
301
301
|
require 'yaml'
|
302
302
|
if options[:create_config].is_a? String
|
@@ -307,7 +307,7 @@ module Railroader
|
|
307
307
|
|
308
308
|
options.delete :create_config
|
309
309
|
|
310
|
-
options.each do |k,v|
|
310
|
+
options.each do |k, v|
|
311
311
|
if v.is_a? Set
|
312
312
|
options[k] = v.to_a
|
313
313
|
end
|
@@ -331,9 +331,9 @@ module Railroader
|
|
331
331
|
end
|
332
332
|
end
|
333
333
|
|
334
|
-
#Run a scan. Generally called from Railroader.run instead of directly.
|
334
|
+
# Run a scan. Generally called from Railroader.run instead of directly.
|
335
335
|
def self.scan options
|
336
|
-
#Load scanner
|
336
|
+
# Load scanner
|
337
337
|
notify "Loading scanner..."
|
338
338
|
|
339
339
|
begin
|
@@ -344,7 +344,7 @@ module Railroader
|
|
344
344
|
|
345
345
|
add_external_checks options
|
346
346
|
|
347
|
-
#Start scanning
|
347
|
+
# Start scanning
|
348
348
|
scanner = Scanner.new options
|
349
349
|
tracker = scanner.tracker
|
350
350
|
|
@@ -411,17 +411,17 @@ module Railroader
|
|
411
411
|
end
|
412
412
|
private_class_method :write_report_to_formats
|
413
413
|
|
414
|
-
#Rescan a subset of files in a Rails application.
|
414
|
+
# Rescan a subset of files in a Rails application.
|
415
415
|
#
|
416
|
-
#A full scan must have been run already to use this method.
|
417
|
-
#The returned Tracker object from Railroader.run is used as a starting point
|
418
|
-
#for the rescan.
|
416
|
+
# A full scan must have been run already to use this method.
|
417
|
+
# The returned Tracker object from Railroader.run is used as a starting point
|
418
|
+
# for the rescan.
|
419
419
|
#
|
420
|
-
#Options may be given as a hash with the same values as Railroader.run.
|
421
|
-
#Note that these options will be merged into the Tracker.
|
420
|
+
# Options may be given as a hash with the same values as Railroader.run.
|
421
|
+
# Note that these options will be merged into the Tracker.
|
422
422
|
#
|
423
|
-
#This method returns a RescanReport object with information about the scan.
|
424
|
-
#However, the Tracker object will also be modified as the scan is run.
|
423
|
+
# This method returns a RescanReport object with information about the scan.
|
424
|
+
# However, the Tracker object will also be modified as the scan is run.
|
425
425
|
def self.rescan tracker, files, options = {}
|
426
426
|
require 'railroader/rescanner'
|
427
427
|
|
data/lib/ruby_parser/bm_sexp.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
#Sexp changes from ruby_parser
|
2
|
-
#and some changes for caching hash value and tracking 'original' line number
|
3
|
-
#of a Sexp.
|
1
|
+
# Sexp changes from ruby_parser
|
2
|
+
# and some changes for caching hash value and tracking 'original' line number
|
3
|
+
# of a Sexp.
|
4
4
|
class Sexp
|
5
5
|
attr_accessor :original_line, :or_depth
|
6
6
|
ASSIGNMENT_BOOL = [:gasgn, :iasgn, :lasgn, :cvdecl, :cvasgn, :cdecl, :or, :and, :colon2, :op_asgn_or]
|
7
7
|
CALLS = [:call, :attrasgn, :safe_call, :safe_attrasgn]
|
8
8
|
|
9
9
|
def method_missing name, *args
|
10
|
-
#Railroader does not use this functionality,
|
11
|
-
#so overriding it to raise a NoMethodError.
|
10
|
+
# Railroader does not use this functionality,
|
11
|
+
# so overriding it to raise a NoMethodError.
|
12
12
|
#
|
13
|
-
#The original functionality calls find_node and optionally
|
14
|
-
#deletes the node if found.
|
13
|
+
# The original functionality calls find_node and optionally
|
14
|
+
# deletes the node if found.
|
15
15
|
#
|
16
|
-
#Defining a method named "return" seems like a bad idea, so we have to
|
17
|
-
#check for it here instead
|
16
|
+
# Defining a method named "return" seems like a bad idea, so we have to
|
17
|
+
# check for it here instead
|
18
18
|
if name == :return
|
19
19
|
find_node name, *args
|
20
20
|
else
|
@@ -22,8 +22,8 @@ class Sexp
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
#Create clone of Sexp and nested Sexps but not their non-Sexp contents.
|
26
|
-
#If a line number is provided, also sets line/original_line on all Sexps.
|
25
|
+
# Create clone of Sexp and nested Sexps but not their non-Sexp contents.
|
26
|
+
# If a line number is provided, also sets line/original_line on all Sexps.
|
27
27
|
def deep_clone line = nil
|
28
28
|
s = Sexp.new
|
29
29
|
|
@@ -74,9 +74,9 @@ class Sexp
|
|
74
74
|
self[0] = type
|
75
75
|
end
|
76
76
|
|
77
|
-
#Join self and exp into an :or Sexp.
|
78
|
-
#Sets or_depth.
|
79
|
-
#Used for combining "branched" values in AliasProcessor.
|
77
|
+
# Join self and exp into an :or Sexp.
|
78
|
+
# Sets or_depth.
|
79
|
+
# Used for combining "branched" values in AliasProcessor.
|
80
80
|
def combine exp, line = nil
|
81
81
|
combined = Sexp.new(:or, self, exp).line(line || -2)
|
82
82
|
|
@@ -99,10 +99,10 @@ class Sexp
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def hash
|
102
|
-
#There still seems to be some instances in which the hash of the
|
103
|
-
#Sexp changes, but I have not found what method call is doing it.
|
104
|
-
#Of course, Sexp is subclasses from Array, so who knows what might
|
105
|
-
#be going on.
|
102
|
+
# There still seems to be some instances in which the hash of the
|
103
|
+
# Sexp changes, but I have not found what method call is doing it.
|
104
|
+
# Of course, Sexp is subclasses from Array, so who knows what might
|
105
|
+
# be going on.
|
106
106
|
@my_hash_value ||= super
|
107
107
|
end
|
108
108
|
|
@@ -121,33 +121,33 @@ class Sexp
|
|
121
121
|
old_find_node(*args)
|
122
122
|
end
|
123
123
|
|
124
|
-
#Raise a WrongSexpError if the nodes type does not match one of the expected
|
125
|
-
#types.
|
124
|
+
# Raise a WrongSexpError if the nodes type does not match one of the expected
|
125
|
+
# types.
|
126
126
|
def expect *types
|
127
127
|
unless types.include? self.node_type
|
128
128
|
raise WrongSexpError, "Expected #{types.join ' or '} but given #{self.inspect}", caller[1..-1]
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
-
#Returns target of a method call:
|
132
|
+
# Returns target of a method call:
|
133
133
|
#
|
134
|
-
#s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))
|
134
|
+
# s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))
|
135
135
|
# ^-----------target-----------^
|
136
136
|
def target
|
137
137
|
expect :call, :attrasgn, :safe_call, :safe_attrasgn
|
138
138
|
self[1]
|
139
139
|
end
|
140
140
|
|
141
|
-
#Sets the target of a method call:
|
141
|
+
# Sets the target of a method call:
|
142
142
|
def target= exp
|
143
143
|
expect :call, :attrasgn, :safe_call, :safe_attrasgn
|
144
144
|
@my_hash_value = nil
|
145
145
|
self[1] = exp
|
146
146
|
end
|
147
147
|
|
148
|
-
#Returns method of a method call:
|
148
|
+
# Returns method of a method call:
|
149
149
|
#
|
150
|
-
#s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))
|
150
|
+
# s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))
|
151
151
|
# ^- method
|
152
152
|
def method
|
153
153
|
expect :call, :attrasgn, :safe_call, :safe_attrasgn, :super, :zsuper, :result
|
@@ -168,7 +168,7 @@ class Sexp
|
|
168
168
|
self[2] = name
|
169
169
|
end
|
170
170
|
|
171
|
-
#Sets the arglist in a method call.
|
171
|
+
# Sets the arglist in a method call.
|
172
172
|
def arglist= exp
|
173
173
|
expect :call, :attrasgn, :safe_call, :safe_attrasgn
|
174
174
|
@my_hash_value = nil
|
@@ -187,9 +187,9 @@ class Sexp
|
|
187
187
|
self.arglist = exp
|
188
188
|
end
|
189
189
|
|
190
|
-
#Returns arglist for method call. This differs from Sexp#args, as Sexp#args
|
191
|
-
#does not return a 'real' Sexp (it does not have a node type) but
|
192
|
-
#Sexp#arglist returns a s(:arglist, ...)
|
190
|
+
# Returns arglist for method call. This differs from Sexp#args, as Sexp#args
|
191
|
+
# does not return a 'real' Sexp (it does not have a node type) but
|
192
|
+
# Sexp#arglist returns a s(:arglist, ...)
|
193
193
|
#
|
194
194
|
# s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2)))
|
195
195
|
# ^------------ arglist ------------^
|
@@ -208,7 +208,7 @@ class Sexp
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
#Returns arguments of a method call. This will be an 'untyped' Sexp.
|
211
|
+
# Returns arguments of a method call. This will be an 'untyped' Sexp.
|
212
212
|
#
|
213
213
|
# s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2)))
|
214
214
|
# ^--------args--------^
|
@@ -261,26 +261,26 @@ class Sexp
|
|
261
261
|
self.each_arg true, &block
|
262
262
|
end
|
263
263
|
|
264
|
-
#Returns first argument of a method call.
|
264
|
+
# Returns first argument of a method call.
|
265
265
|
def first_arg
|
266
266
|
expect :call, :attrasgn, :safe_call, :safe_attrasgn
|
267
267
|
self[3]
|
268
268
|
end
|
269
269
|
|
270
|
-
#Sets first argument of a method call.
|
270
|
+
# Sets first argument of a method call.
|
271
271
|
def first_arg= exp
|
272
272
|
expect :call, :attrasgn, :safe_call, :safe_attrasgn
|
273
273
|
@my_hash_value = nil
|
274
274
|
self[3] = exp
|
275
275
|
end
|
276
276
|
|
277
|
-
#Returns second argument of a method call.
|
277
|
+
# Returns second argument of a method call.
|
278
278
|
def second_arg
|
279
279
|
expect :call, :attrasgn, :safe_call, :safe_attrasgn
|
280
280
|
self[4]
|
281
281
|
end
|
282
282
|
|
283
|
-
#Sets second argument of a method call.
|
283
|
+
# Sets second argument of a method call.
|
284
284
|
def second_arg= exp
|
285
285
|
expect :call, :attrasgn, :safe_call, :safe_attrasgn
|
286
286
|
@my_hash_value = nil
|
@@ -314,7 +314,7 @@ class Sexp
|
|
314
314
|
chain = []
|
315
315
|
call = self
|
316
316
|
|
317
|
-
while call.class == Sexp and CALLS.include? call.first
|
317
|
+
while call.class == Sexp and CALLS.include? call.first
|
318
318
|
chain << call.method
|
319
319
|
call = call.target
|
320
320
|
end
|
@@ -323,7 +323,7 @@ class Sexp
|
|
323
323
|
chain
|
324
324
|
end
|
325
325
|
|
326
|
-
#Returns condition of an if expression:
|
326
|
+
# Returns condition of an if expression:
|
327
327
|
#
|
328
328
|
# s(:if,
|
329
329
|
# s(:lvar, :condition), <-- condition
|
@@ -340,7 +340,7 @@ class Sexp
|
|
340
340
|
end
|
341
341
|
|
342
342
|
|
343
|
-
#Returns 'then' clause of an if expression:
|
343
|
+
# Returns 'then' clause of an if expression:
|
344
344
|
#
|
345
345
|
# s(:if,
|
346
346
|
# s(:lvar, :condition),
|
@@ -351,7 +351,7 @@ class Sexp
|
|
351
351
|
self[2]
|
352
352
|
end
|
353
353
|
|
354
|
-
#Returns 'else' clause of an if expression:
|
354
|
+
# Returns 'else' clause of an if expression:
|
355
355
|
#
|
356
356
|
# s(:if,
|
357
357
|
# s(:lvar, :condition),
|
@@ -363,7 +363,7 @@ class Sexp
|
|
363
363
|
self[3]
|
364
364
|
end
|
365
365
|
|
366
|
-
#Method call associated with a block:
|
366
|
+
# Method call associated with a block:
|
367
367
|
#
|
368
368
|
# s(:iter,
|
369
369
|
# s(:call, nil, :x, s(:arglist)), <- block_call
|
@@ -374,8 +374,8 @@ class Sexp
|
|
374
374
|
self[1]
|
375
375
|
end
|
376
376
|
|
377
|
-
#Returns block of a call with a block.
|
378
|
-
#Could be a single expression or a block:
|
377
|
+
# Returns block of a call with a block.
|
378
|
+
# Could be a single expression or a block:
|
379
379
|
#
|
380
380
|
# s(:iter,
|
381
381
|
# s(:call, nil, :x, s(:arglist)),
|
@@ -383,7 +383,7 @@ class Sexp
|
|
383
383
|
# s(:block, s(:lvar, :y), s(:call, nil, :z, s(:arglist))))
|
384
384
|
# ^-------------------- block --------------------------^
|
385
385
|
def block delete = nil
|
386
|
-
unless delete.nil? #this is from RubyParser
|
386
|
+
unless delete.nil? # this is from RubyParser
|
387
387
|
return find_node :block, delete
|
388
388
|
end
|
389
389
|
|
@@ -395,12 +395,12 @@ class Sexp
|
|
395
395
|
when :scope
|
396
396
|
self[1]
|
397
397
|
when :resbody
|
398
|
-
#This is for Ruby2Ruby ONLY
|
398
|
+
# This is for Ruby2Ruby ONLY
|
399
399
|
find_node :block
|
400
400
|
end
|
401
401
|
end
|
402
402
|
|
403
|
-
#Returns parameters for a block
|
403
|
+
# Returns parameters for a block
|
404
404
|
#
|
405
405
|
# s(:iter,
|
406
406
|
# s(:call, nil, :x, s(:arglist)),
|
@@ -420,7 +420,7 @@ class Sexp
|
|
420
420
|
self[1]
|
421
421
|
end
|
422
422
|
|
423
|
-
#Returns the left hand side of assignment or boolean:
|
423
|
+
# Returns the left hand side of assignment or boolean:
|
424
424
|
#
|
425
425
|
# s(:lasgn, :x, s(:lit, 1))
|
426
426
|
# ^--lhs
|
@@ -429,14 +429,14 @@ class Sexp
|
|
429
429
|
self[1]
|
430
430
|
end
|
431
431
|
|
432
|
-
#Sets the left hand side of assignment or boolean.
|
432
|
+
# Sets the left hand side of assignment or boolean.
|
433
433
|
def lhs= exp
|
434
434
|
expect(*ASSIGNMENT_BOOL)
|
435
435
|
@my_hash_value = nil
|
436
436
|
self[1] = exp
|
437
437
|
end
|
438
438
|
|
439
|
-
#Returns right side (value) of assignment or boolean:
|
439
|
+
# Returns right side (value) of assignment or boolean:
|
440
440
|
#
|
441
441
|
# s(:lasgn, :x, s(:lit, 1))
|
442
442
|
# ^--rhs---^
|
@@ -454,7 +454,7 @@ class Sexp
|
|
454
454
|
end
|
455
455
|
end
|
456
456
|
|
457
|
-
#Sets the right hand side of assignment or boolean.
|
457
|
+
# Sets the right hand side of assignment or boolean.
|
458
458
|
def rhs= exp
|
459
459
|
expect :attrasgn, :safe_attrasgn, *ASSIGNMENT_BOOL
|
460
460
|
@my_hash_value = nil
|
@@ -466,7 +466,7 @@ class Sexp
|
|
466
466
|
end
|
467
467
|
end
|
468
468
|
|
469
|
-
#Returns name of method being defined in a method definition.
|
469
|
+
# Returns name of method being defined in a method definition.
|
470
470
|
def method_name
|
471
471
|
expect :defn, :defs
|
472
472
|
|
@@ -489,8 +489,8 @@ class Sexp
|
|
489
489
|
end
|
490
490
|
end
|
491
491
|
|
492
|
-
#Sets body, which is now a complicated process because the body is no longer
|
493
|
-
#a separate Sexp, but just a list of Sexps.
|
492
|
+
# Sets body, which is now a complicated process because the body is no longer
|
493
|
+
# a separate Sexp, but just a list of Sexps.
|
494
494
|
def body= exp
|
495
495
|
expect :defn, :defs, :class, :module
|
496
496
|
@my_hash_value = nil
|
@@ -504,21 +504,21 @@ class Sexp
|
|
504
504
|
index = 2
|
505
505
|
end
|
506
506
|
|
507
|
-
self.slice!(index..-1) #Remove old body
|
507
|
+
self.slice!(index..-1) # Remove old body
|
508
508
|
|
509
509
|
if exp.first == :rlist
|
510
510
|
exp = exp[1..-1]
|
511
511
|
end
|
512
512
|
|
513
|
-
#Insert new body
|
513
|
+
# Insert new body
|
514
514
|
exp.each do |e|
|
515
515
|
self[index] = e
|
516
516
|
index += 1
|
517
517
|
end
|
518
518
|
end
|
519
519
|
|
520
|
-
#Returns body of a method definition, class, or module.
|
521
|
-
#This will be an untyped Sexp containing a list of Sexps from the body.
|
520
|
+
# Returns body of a method definition, class, or module.
|
521
|
+
# This will be an untyped Sexp containing a list of Sexps from the body.
|
522
522
|
def body
|
523
523
|
expect :defn, :defs, :class, :module
|
524
524
|
|
@@ -532,8 +532,8 @@ class Sexp
|
|
532
532
|
end
|
533
533
|
end
|
534
534
|
|
535
|
-
#Like Sexp#body, except the returned Sexp is of type :rlist
|
536
|
-
#instead of untyped.
|
535
|
+
# Like Sexp#body, except the returned Sexp is of type :rlist
|
536
|
+
# instead of untyped.
|
537
537
|
def body_list
|
538
538
|
self.body.unshift :rlist
|
539
539
|
end
|
@@ -555,21 +555,21 @@ class Sexp
|
|
555
555
|
self[2]
|
556
556
|
end
|
557
557
|
|
558
|
-
#Returns the call Sexp in a result returned from FindCall
|
558
|
+
# Returns the call Sexp in a result returned from FindCall
|
559
559
|
def call
|
560
560
|
expect :result
|
561
561
|
|
562
562
|
self.last
|
563
563
|
end
|
564
564
|
|
565
|
-
#Returns the module the call is inside
|
565
|
+
# Returns the module the call is inside
|
566
566
|
def module
|
567
567
|
expect :result
|
568
568
|
|
569
569
|
self[1]
|
570
570
|
end
|
571
571
|
|
572
|
-
#Return the class the call is inside
|
572
|
+
# Return the class the call is inside
|
573
573
|
def result_class
|
574
574
|
expect :result
|
575
575
|
|
@@ -595,7 +595,7 @@ class Sexp
|
|
595
595
|
end
|
596
596
|
end
|
597
597
|
|
598
|
-
#Invalidate hash cache if the Sexp changes
|
598
|
+
# Invalidate hash cache if the Sexp changes
|
599
599
|
[:[]=, :clear, :collect!, :compact!, :concat, :delete, :delete_at,
|
600
600
|
:delete_if, :drop, :drop_while, :fill, :flatten!, :replace, :insert,
|
601
601
|
:keep_if, :map!, :pop, :push, :reject!, :replace, :reverse!, :rotate!,
|
@@ -610,8 +610,8 @@ end
|
|
610
610
|
RUBY
|
611
611
|
end
|
612
612
|
|
613
|
-
#Methods used by RubyParser which would normally go through method_missing but
|
614
|
-
#we don't want that to happen because it hides Railroader errors
|
613
|
+
# Methods used by RubyParser which would normally go through method_missing but
|
614
|
+
# we don't want that to happen because it hides Railroader errors
|
615
615
|
[:resbody, :lasgn, :iasgn, :splat].each do |method|
|
616
616
|
Sexp.class_eval <<-RUBY
|
617
617
|
def #{method} delete = false
|
@@ -42,7 +42,7 @@ class Railroader::SexpProcessor
|
|
42
42
|
# SexpProcessor
|
43
43
|
|
44
44
|
def initialize
|
45
|
-
@expected
|
45
|
+
@expected = Sexp
|
46
46
|
@processors = self.class.processors
|
47
47
|
@context = []
|
48
48
|
|
@@ -77,9 +77,9 @@ class Railroader::SexpProcessor
|
|
77
77
|
result = self.process_default(exp)
|
78
78
|
end
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
raise SexpTypeError, "Result must be a #{@expected}, was #{result.class}:#{result.inspect}" unless @expected === result
|
82
|
-
|
82
|
+
|
83
83
|
result
|
84
84
|
end
|
85
85
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railroader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.3.
|
4
|
+
version: 4.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David A. Wheeler and Justin Collins
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
11
|
- railroader-public_cert.pem
|
12
|
-
date: 2019-05-
|
12
|
+
date: 2019-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby_parser
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 3.
|
20
|
+
version: 3.13.1
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 3.
|
27
|
+
version: 3.13.1
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: sexp_processor
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|