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
@@ -4,9 +4,9 @@ require 'railroader/processors/lib/processor_helper'
|
|
4
4
|
require 'railroader/processors/lib/safe_call_helper'
|
5
5
|
require 'railroader/processors/lib/call_conversion_helper'
|
6
6
|
|
7
|
-
#Returns an s-expression with aliases replaced with their value.
|
8
|
-
#This does not preserve semantics (due to side effects, etc.), but it makes
|
9
|
-
#processing easier when searching for various things.
|
7
|
+
# Returns an s-expression with aliases replaced with their value.
|
8
|
+
# This does not preserve semantics (due to side effects, etc.), but it makes
|
9
|
+
# processing easier when searching for various things.
|
10
10
|
class Railroader::AliasProcessor < Railroader::SexpProcessor
|
11
11
|
include Railroader::ProcessorHelper
|
12
12
|
include Railroader::SafeCallHelper
|
@@ -15,9 +15,9 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
15
15
|
|
16
16
|
attr_reader :result, :tracker
|
17
17
|
|
18
|
-
#Returns a new AliasProcessor with an empty environment.
|
18
|
+
# Returns a new AliasProcessor with an empty environment.
|
19
19
|
#
|
20
|
-
#The recommended usage is:
|
20
|
+
# The recommended usage is:
|
21
21
|
#
|
22
22
|
# AliasProcessor.new.process_safely src
|
23
23
|
def initialize tracker = nil, file_name = nil
|
@@ -27,23 +27,23 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
27
27
|
@ignore_ifs = nil
|
28
28
|
@exp_context = []
|
29
29
|
@current_module = nil
|
30
|
-
@tracker = tracker #set in subclass as necessary
|
30
|
+
@tracker = tracker # set in subclass as necessary
|
31
31
|
@helper_method_cache = {}
|
32
32
|
@helper_method_info = Hash.new({})
|
33
|
-
@or_depth_limit = (tracker && tracker.options[:branch_limit]) || 5 #arbitrary default
|
33
|
+
@or_depth_limit = (tracker && tracker.options[:branch_limit]) || 5 # arbitrary default
|
34
34
|
@meth_env = nil
|
35
35
|
@file_name = file_name
|
36
36
|
set_env_defaults
|
37
37
|
end
|
38
38
|
|
39
|
-
#This method processes the given Sexp, but copies it first so
|
40
|
-
#the original argument will not be modified.
|
39
|
+
# This method processes the given Sexp, but copies it first so
|
40
|
+
# the original argument will not be modified.
|
41
41
|
#
|
42
|
-
#_set_env_ should be an instance of SexpProcessor::Environment. If provided,
|
43
|
-
#it will be used as the starting environment.
|
42
|
+
# _set_env_ should be an instance of SexpProcessor::Environment. If provided,
|
43
|
+
# it will be used as the starting environment.
|
44
44
|
#
|
45
|
-
#This method returns a new Sexp with variables replaced with their values,
|
46
|
-
#where possible.
|
45
|
+
# This method returns a new Sexp with variables replaced with their values,
|
46
|
+
# where possible.
|
47
47
|
def process_safely src, set_env = nil, file_name = nil
|
48
48
|
@file_name = file_name
|
49
49
|
@env = set_env || SexpProcessor::Environment.new
|
@@ -52,8 +52,8 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
52
52
|
@result
|
53
53
|
end
|
54
54
|
|
55
|
-
#Process a Sexp. If the Sexp has a value associated with it in the
|
56
|
-
#environment, that value will be returned.
|
55
|
+
# Process a Sexp. If the Sexp has a value associated with it in the
|
56
|
+
# environment, that value will be returned.
|
57
57
|
def process_default exp
|
58
58
|
@exp_context.push exp
|
59
59
|
|
@@ -160,7 +160,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
160
160
|
HASH_CONST = s(:const, :Hash)
|
161
161
|
RAILS_TEST = s(:call, s(:call, s(:const, :Rails), :env), :test?)
|
162
162
|
|
163
|
-
#Process a method call.
|
163
|
+
# Process a method call.
|
164
164
|
def process_call exp
|
165
165
|
return exp if process_call_defn? exp
|
166
166
|
target_var = exp.target
|
@@ -175,7 +175,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
175
175
|
exp = process_default exp
|
176
176
|
end
|
177
177
|
|
178
|
-
#In case it is replaced with something else
|
178
|
+
# In case it is replaced with something else
|
179
179
|
unless call? exp
|
180
180
|
return exp
|
181
181
|
end
|
@@ -199,8 +199,8 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
199
199
|
return Sexp.new(:false)
|
200
200
|
end
|
201
201
|
|
202
|
-
#See if it is possible to simplify some basic cases
|
203
|
-
#of addition/concatenation.
|
202
|
+
# See if it is possible to simplify some basic cases
|
203
|
+
# of addition/concatenation.
|
204
204
|
case method
|
205
205
|
when :+
|
206
206
|
if array? target and array? first_arg
|
@@ -351,7 +351,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
351
351
|
env.current[local] = safe_literal(exp.line)
|
352
352
|
else
|
353
353
|
block_args.each do |e|
|
354
|
-
#Force block arg(s) to be local
|
354
|
+
# Force block arg(s) to be local
|
355
355
|
if node_type? e, :lasgn
|
356
356
|
env.current[Sexp.new(:lvar, e.lhs)] = Sexp.new(:lvar, e.lhs)
|
357
357
|
elsif node_type? e, :kwarg
|
@@ -382,7 +382,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
382
382
|
exp
|
383
383
|
end
|
384
384
|
|
385
|
-
#Process a new scope.
|
385
|
+
# Process a new scope.
|
386
386
|
def process_scope exp
|
387
387
|
env.scope do
|
388
388
|
process exp.block
|
@@ -390,14 +390,14 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
390
390
|
exp
|
391
391
|
end
|
392
392
|
|
393
|
-
#Start new scope for block.
|
393
|
+
# Start new scope for block.
|
394
394
|
def process_block exp
|
395
395
|
env.scope do
|
396
396
|
process_default exp
|
397
397
|
end
|
398
398
|
end
|
399
399
|
|
400
|
-
#Process a method definition.
|
400
|
+
# Process a method definition.
|
401
401
|
def process_defn exp
|
402
402
|
meth_env do
|
403
403
|
exp.body = process_all! exp.body
|
@@ -417,7 +417,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
417
417
|
end
|
418
418
|
end
|
419
419
|
|
420
|
-
#Process a method definition on self.
|
420
|
+
# Process a method definition on self.
|
421
421
|
def process_defs exp
|
422
422
|
env.scope do
|
423
423
|
set_env_defaults
|
@@ -435,7 +435,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
435
435
|
end
|
436
436
|
end
|
437
437
|
|
438
|
-
#Local assignment
|
438
|
+
# Local assignment
|
439
439
|
# x = 1
|
440
440
|
def process_lasgn exp
|
441
441
|
self_assign = self_assign?(exp.lhs, exp.rhs)
|
@@ -454,7 +454,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
454
454
|
exp
|
455
455
|
end
|
456
456
|
|
457
|
-
#Instance variable assignment
|
457
|
+
# Instance variable assignment
|
458
458
|
# @x = 1
|
459
459
|
def process_iasgn exp
|
460
460
|
self_assign = self_assign?(exp.lhs, exp.rhs)
|
@@ -474,7 +474,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
474
474
|
exp
|
475
475
|
end
|
476
476
|
|
477
|
-
#Global assignment
|
477
|
+
# Global assignment
|
478
478
|
# $x = 1
|
479
479
|
def process_gasgn exp
|
480
480
|
match = Sexp.new(:gvar, exp.lhs)
|
@@ -490,7 +490,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
490
490
|
exp
|
491
491
|
end
|
492
492
|
|
493
|
-
#Class variable assignment
|
493
|
+
# Class variable assignment
|
494
494
|
# @@x = 1
|
495
495
|
def process_cvdecl exp
|
496
496
|
match = Sexp.new(:cvar, exp.lhs)
|
@@ -502,9 +502,9 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
502
502
|
exp
|
503
503
|
end
|
504
504
|
|
505
|
-
#'Attribute' assignment
|
505
|
+
# 'Attribute' assignment
|
506
506
|
# x.y = 1
|
507
|
-
#or
|
507
|
+
# or
|
508
508
|
# x[:y] = 1
|
509
509
|
def process_attrasgn exp
|
510
510
|
tar_variable = exp.target
|
@@ -527,10 +527,10 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
527
527
|
unless node_type? target, :hash
|
528
528
|
exp.target = target
|
529
529
|
end
|
530
|
-
elsif method.to_s[-1,1] == "="
|
530
|
+
elsif method.to_s[-1, 1] == "="
|
531
531
|
exp.first_arg = process(index_arg)
|
532
532
|
value = get_rhs(exp)
|
533
|
-
#This is what we'll replace with the value
|
533
|
+
# This is what we'll replace with the value
|
534
534
|
match = Sexp.new(:call, target, method.to_s[0..-2].to_sym)
|
535
535
|
|
536
536
|
set_value match, value
|
@@ -585,7 +585,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
585
585
|
exp
|
586
586
|
end
|
587
587
|
|
588
|
-
#Merge values into hash when processing
|
588
|
+
# Merge values into hash when processing
|
589
589
|
#
|
590
590
|
# h.merge! :something => "value"
|
591
591
|
def process_hash_merge! hash, args
|
@@ -598,7 +598,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
598
598
|
hash
|
599
599
|
end
|
600
600
|
|
601
|
-
#Return a new hash Sexp with the given values merged into it.
|
601
|
+
# Return a new hash Sexp with the given values merged into it.
|
602
602
|
#
|
603
603
|
#+args+ should be a hash Sexp as well.
|
604
604
|
def process_hash_merge hash, args
|
@@ -609,7 +609,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
609
609
|
hash
|
610
610
|
end
|
611
611
|
|
612
|
-
#Assignments like this
|
612
|
+
# Assignments like this
|
613
613
|
# x[:y] ||= 1
|
614
614
|
def process_op_asgn1 exp
|
615
615
|
target_var = exp[1]
|
@@ -637,7 +637,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
637
637
|
exp
|
638
638
|
end
|
639
639
|
|
640
|
-
#Assignments like this
|
640
|
+
# Assignments like this
|
641
641
|
# x.y ||= 1
|
642
642
|
def process_op_asgn2 exp
|
643
643
|
return process_default(exp) if exp[3] != :"||"
|
@@ -655,13 +655,13 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
655
655
|
exp
|
656
656
|
end
|
657
657
|
|
658
|
-
#This is the right hand side value of a multiple assignment,
|
659
|
-
#like `x = y, z`
|
658
|
+
# This is the right hand side value of a multiple assignment,
|
659
|
+
# like `x = y, z`
|
660
660
|
def process_svalue exp
|
661
661
|
exp.value
|
662
662
|
end
|
663
663
|
|
664
|
-
#Constant assignments like
|
664
|
+
# Constant assignments like
|
665
665
|
# BIG_CONSTANT = 234810983
|
666
666
|
def process_cdecl exp
|
667
667
|
if sexp? exp.rhs
|
@@ -706,7 +706,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
706
706
|
all_literals? exp.target
|
707
707
|
end
|
708
708
|
|
709
|
-
#Sets @inside_if = true
|
709
|
+
# Sets @inside_if = true
|
710
710
|
def process_if exp
|
711
711
|
if @ignore_ifs.nil?
|
712
712
|
@ignore_ifs = @tracker && @tracker.options[:ignore_ifs]
|
@@ -714,7 +714,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
714
714
|
|
715
715
|
condition = exp.condition = process exp.condition
|
716
716
|
|
717
|
-
#Check if a branch is obviously going to be taken
|
717
|
+
# Check if a branch is obviously going to be taken
|
718
718
|
if true? condition
|
719
719
|
no_branch = true
|
720
720
|
exps = [exp.then_clause, nil]
|
@@ -904,22 +904,22 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
904
904
|
end
|
905
905
|
end
|
906
906
|
|
907
|
-
#Returns a new SexpProcessor::Environment containing only instance variables.
|
908
|
-
#This is useful, for example, when processing views.
|
907
|
+
# Returns a new SexpProcessor::Environment containing only instance variables.
|
908
|
+
# This is useful, for example, when processing views.
|
909
909
|
def only_ivars include_request_vars = false, lenv = nil
|
910
910
|
lenv ||= env
|
911
911
|
res = SexpProcessor::Environment.new
|
912
912
|
|
913
913
|
if include_request_vars
|
914
914
|
lenv.all.each do |k, v|
|
915
|
-
#TODO Why would this have nil values?
|
915
|
+
# TODO Why would this have nil values?
|
916
916
|
if (k.node_type == :ivar or request_value? k) and not v.nil?
|
917
917
|
res[k] = v.dup
|
918
918
|
end
|
919
919
|
end
|
920
920
|
else
|
921
921
|
lenv.all.each do |k, v|
|
922
|
-
#TODO Why would this have nil values?
|
922
|
+
# TODO Why would this have nil values?
|
923
923
|
if k.node_type == :ivar and not v.nil?
|
924
924
|
res[k] = v.dup
|
925
925
|
end
|
@@ -944,7 +944,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
944
944
|
def get_call_value call
|
945
945
|
method_name = call.method
|
946
946
|
|
947
|
-
#Look for helper methods and see if we can get a return value
|
947
|
+
# Look for helper methods and see if we can get a return value
|
948
948
|
if found_method = find_method(method_name, @current_class)
|
949
949
|
helper = found_method[:method]
|
950
950
|
|
@@ -966,24 +966,24 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
966
966
|
|
967
967
|
info = @helper_method_info[method_name]
|
968
968
|
|
969
|
-
#If method uses instance variables, then include those and request
|
970
|
-
#variables (params, etc) in the method environment. Otherwise,
|
971
|
-
#only include request variables.
|
969
|
+
# If method uses instance variables, then include those and request
|
970
|
+
# variables (params, etc) in the method environment. Otherwise,
|
971
|
+
# only include request variables.
|
972
972
|
if info[:uses_ivars]
|
973
973
|
meth_env = only_ivars(:include_request_vars)
|
974
974
|
else
|
975
975
|
meth_env = only_request_vars
|
976
976
|
end
|
977
977
|
|
978
|
-
#Add arguments to method environment
|
978
|
+
# Add arguments to method environment
|
979
979
|
assign_args method_exp, args, meth_env
|
980
980
|
|
981
981
|
|
982
|
-
#Find return values if method does not depend on environment/args
|
982
|
+
# Find return values if method does not depend on environment/args
|
983
983
|
values = @helper_method_cache[method_name]
|
984
984
|
|
985
985
|
unless values
|
986
|
-
#Serialize environment for cache key
|
986
|
+
# Serialize environment for cache key
|
987
987
|
meth_values = meth_env.instance_variable_get(:@env).to_a
|
988
988
|
meth_values.sort!
|
989
989
|
meth_values = meth_values.to_s
|
@@ -994,14 +994,14 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
994
994
|
end
|
995
995
|
|
996
996
|
if values
|
997
|
-
#Use values from cache
|
997
|
+
# Use values from cache
|
998
998
|
values[:ivar_values].each do |var, val|
|
999
999
|
env[var] = val
|
1000
1000
|
end
|
1001
1001
|
|
1002
1002
|
values[:return_value]
|
1003
1003
|
else
|
1004
|
-
#Find return value for method
|
1004
|
+
# Find return value for method
|
1005
1005
|
frv = Railroader::FindReturnValue.new
|
1006
1006
|
value = frv.get_return_value(method_exp.body_list, meth_env)
|
1007
1007
|
|
@@ -1013,13 +1013,13 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1013
1013
|
end
|
1014
1014
|
|
1015
1015
|
if not frv.uses_ivars? and args.length == 0
|
1016
|
-
#Store return value without ivars and args if they are not used
|
1016
|
+
# Store return value without ivars and args if they are not used
|
1017
1017
|
@helper_method_cache[method_exp.method_name] = { :return_value => value, :ivar_values => ivars }
|
1018
1018
|
else
|
1019
1019
|
@helper_method_cache[digest] = { :return_value => value, :ivar_values => ivars }
|
1020
1020
|
end
|
1021
1021
|
|
1022
|
-
#Store information about method, just ivar usage for now
|
1022
|
+
# Store information about method, just ivar usage for now
|
1023
1023
|
@helper_method_info[method_name] = { :uses_ivars => frv.uses_ivars? }
|
1024
1024
|
|
1025
1025
|
value
|
@@ -1040,7 +1040,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1040
1040
|
meth_env
|
1041
1041
|
end
|
1042
1042
|
|
1043
|
-
#Finds the inner most call target which is not the target of a call to <<
|
1043
|
+
# Finds the inner most call target which is not the target of a call to <<
|
1044
1044
|
def find_push_target exp
|
1045
1045
|
if call? exp and exp.method == :<<
|
1046
1046
|
find_push_target exp.target
|
@@ -1061,8 +1061,8 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1061
1061
|
nil
|
1062
1062
|
end
|
1063
1063
|
|
1064
|
-
#Return true if lhs == rhs or lhs is an or expression and
|
1065
|
-
#rhs is one of its values
|
1064
|
+
# Return true if lhs == rhs or lhs is an or expression and
|
1065
|
+
# rhs is one of its values
|
1066
1066
|
def same_value? lhs, rhs
|
1067
1067
|
if lhs == rhs
|
1068
1068
|
true
|
@@ -1077,7 +1077,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1077
1077
|
self_assign_var?(var, value) or self_assign_target?(var, value)
|
1078
1078
|
end
|
1079
1079
|
|
1080
|
-
#Return true if for x += blah or @x += blah
|
1080
|
+
# Return true if for x += blah or @x += blah
|
1081
1081
|
def self_assign_var? var, value
|
1082
1082
|
call? value and
|
1083
1083
|
value.method == :+ and
|
@@ -1085,7 +1085,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1085
1085
|
value.target.value == var
|
1086
1086
|
end
|
1087
1087
|
|
1088
|
-
#Return true for x = x.blah
|
1088
|
+
# Return true for x = x.blah
|
1089
1089
|
def self_assign_target? var, value
|
1090
1090
|
target = top_target(value)
|
1091
1091
|
|
@@ -1096,7 +1096,7 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1096
1096
|
var == target
|
1097
1097
|
end
|
1098
1098
|
|
1099
|
-
#Returns last non-nil target in a call chain
|
1099
|
+
# Returns last non-nil target in a call chain
|
1100
1100
|
def top_target exp, last = nil
|
1101
1101
|
if call? exp
|
1102
1102
|
top_target exp.target, exp
|
@@ -1109,8 +1109,8 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1109
1109
|
|
1110
1110
|
def value_from_if exp
|
1111
1111
|
if block? exp.else_clause or block? exp.then_clause
|
1112
|
-
#If either clause is more than a single expression, just use entire
|
1113
|
-
#if expression for now
|
1112
|
+
# If either clause is more than a single expression, just use entire
|
1113
|
+
# if expression for now
|
1114
1114
|
exp
|
1115
1115
|
elsif exp.else_clause.nil?
|
1116
1116
|
exp.then_clause
|
@@ -1159,10 +1159,10 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1159
1159
|
call? exp and exp.method == :raise
|
1160
1160
|
end
|
1161
1161
|
|
1162
|
-
#Set variable to given value.
|
1163
|
-
#Creates "branched" versions of values when appropriate.
|
1164
|
-
#Avoids creating multiple branched versions inside same
|
1165
|
-
#if branch.
|
1162
|
+
# Set variable to given value.
|
1163
|
+
# Creates "branched" versions of values when appropriate.
|
1164
|
+
# Avoids creating multiple branched versions inside same
|
1165
|
+
# if branch.
|
1166
1166
|
def set_value var, value
|
1167
1167
|
if node_type? value, :if
|
1168
1168
|
value = value_from_if(value)
|
@@ -1187,16 +1187,16 @@ class Railroader::AliasProcessor < Railroader::SexpProcessor
|
|
1187
1187
|
end
|
1188
1188
|
end
|
1189
1189
|
|
1190
|
-
#If possible, distribute operation over both sides of an or.
|
1191
|
-
#For example,
|
1190
|
+
# If possible, distribute operation over both sides of an or.
|
1191
|
+
# For example,
|
1192
1192
|
#
|
1193
1193
|
# (1 or 2) * 5
|
1194
1194
|
#
|
1195
|
-
#Becomes
|
1195
|
+
# Becomes
|
1196
1196
|
#
|
1197
1197
|
# (5 or 10)
|
1198
1198
|
#
|
1199
|
-
#Only works for strings and numbers right now.
|
1199
|
+
# Only works for strings and numbers right now.
|
1200
1200
|
def process_or_simple_operation exp
|
1201
1201
|
arg = exp.first_arg
|
1202
1202
|
return nil unless string? arg or number? arg
|
@@ -2,7 +2,7 @@ require 'railroader/processors/lib/processor_helper'
|
|
2
2
|
require 'railroader/processors/lib/safe_call_helper'
|
3
3
|
require 'railroader/util'
|
4
4
|
|
5
|
-
#Base processor for most processors.
|
5
|
+
# Base processor for most processors.
|
6
6
|
class Railroader::BaseProcessor < Railroader::SexpProcessor
|
7
7
|
include Railroader::ProcessorHelper
|
8
8
|
include Railroader::SafeCallHelper
|
@@ -10,7 +10,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
10
10
|
|
11
11
|
IGNORE = Sexp.new :ignore
|
12
12
|
|
13
|
-
#Return a new Processor.
|
13
|
+
# Return a new Processor.
|
14
14
|
def initialize tracker
|
15
15
|
super()
|
16
16
|
@last = nil
|
@@ -27,12 +27,12 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
27
27
|
IGNORE
|
28
28
|
end
|
29
29
|
|
30
|
-
#Process a new scope. Removes expressions that are set to nil.
|
30
|
+
# Process a new scope. Removes expressions that are set to nil.
|
31
31
|
def process_scope exp
|
32
|
-
#NOPE?
|
32
|
+
# NOPE?
|
33
33
|
end
|
34
34
|
|
35
|
-
#Default processing.
|
35
|
+
# Default processing.
|
36
36
|
def process_default exp
|
37
37
|
exp = exp.dup
|
38
38
|
|
@@ -43,7 +43,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
43
43
|
exp
|
44
44
|
end
|
45
45
|
|
46
|
-
#Process an if statement.
|
46
|
+
# Process an if statement.
|
47
47
|
def process_if exp
|
48
48
|
exp = exp.dup
|
49
49
|
condition = exp[1] = process exp.condition
|
@@ -62,13 +62,13 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
62
62
|
exp
|
63
63
|
end
|
64
64
|
|
65
|
-
#Processes calls with blocks.
|
65
|
+
# Processes calls with blocks.
|
66
66
|
#
|
67
|
-
#s(:iter, CALL, {:lasgn|:masgn}, BLOCK)
|
67
|
+
# s(:iter, CALL, {:lasgn|:masgn}, BLOCK)
|
68
68
|
def process_iter exp
|
69
69
|
exp = exp.dup
|
70
70
|
call = process exp.block_call
|
71
|
-
#deal with assignments somehow
|
71
|
+
# deal with assignments somehow
|
72
72
|
if exp.block
|
73
73
|
block = process exp.block
|
74
74
|
block = nil if block.empty?
|
@@ -81,7 +81,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
81
81
|
call
|
82
82
|
end
|
83
83
|
|
84
|
-
#String with interpolation.
|
84
|
+
# String with interpolation.
|
85
85
|
def process_dstr exp
|
86
86
|
exp = exp.dup
|
87
87
|
exp.shift
|
@@ -101,7 +101,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
101
101
|
exp.unshift :dstr
|
102
102
|
end
|
103
103
|
|
104
|
-
#Processes a block. Changes Sexp node type to :rlist
|
104
|
+
# Processes a block. Changes Sexp node type to :rlist
|
105
105
|
def process_block exp
|
106
106
|
exp = exp.dup
|
107
107
|
exp.shift
|
@@ -113,7 +113,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
113
113
|
exp.unshift :rlist
|
114
114
|
end
|
115
115
|
|
116
|
-
#Processes the inside of an interpolated String.
|
116
|
+
# Processes the inside of an interpolated String.
|
117
117
|
def process_evstr exp
|
118
118
|
exp = exp.dup
|
119
119
|
if exp[1]
|
@@ -123,7 +123,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
123
123
|
exp
|
124
124
|
end
|
125
125
|
|
126
|
-
#Processes a hash
|
126
|
+
# Processes a hash
|
127
127
|
def process_hash exp
|
128
128
|
exp = exp.dup
|
129
129
|
exp.shift
|
@@ -138,7 +138,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
138
138
|
exp.unshift :hash
|
139
139
|
end
|
140
140
|
|
141
|
-
#Processes the values in an argument list
|
141
|
+
# Processes the values in an argument list
|
142
142
|
def process_arglist exp
|
143
143
|
exp = exp.dup
|
144
144
|
exp.shift
|
@@ -149,7 +149,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
149
149
|
exp.unshift :arglist
|
150
150
|
end
|
151
151
|
|
152
|
-
#Processes a local assignment
|
152
|
+
# Processes a local assignment
|
153
153
|
def process_lasgn exp
|
154
154
|
exp = exp.dup
|
155
155
|
exp.rhs = process exp.rhs
|
@@ -158,14 +158,14 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
158
158
|
|
159
159
|
alias :process_iasgn :process_lasgn
|
160
160
|
|
161
|
-
#Processes an instance variable assignment
|
161
|
+
# Processes an instance variable assignment
|
162
162
|
def process_iasgn exp
|
163
163
|
exp = exp.dup
|
164
164
|
exp.rhs = process exp.rhs
|
165
165
|
exp
|
166
166
|
end
|
167
167
|
|
168
|
-
#Processes an attribute assignment, which can be either x.y = 1 or x[:y] = 1
|
168
|
+
# Processes an attribute assignment, which can be either x.y = 1 or x[:y] = 1
|
169
169
|
def process_attrasgn exp
|
170
170
|
exp = exp.dup
|
171
171
|
exp.target = process exp.target
|
@@ -173,7 +173,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
173
173
|
exp
|
174
174
|
end
|
175
175
|
|
176
|
-
#Ignore ignore Sexps
|
176
|
+
# Ignore ignore Sexps
|
177
177
|
def process_ignore exp
|
178
178
|
exp
|
179
179
|
end
|
@@ -191,13 +191,13 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
191
191
|
exp
|
192
192
|
end
|
193
193
|
|
194
|
-
#Convenience method for `make_render exp, true`
|
194
|
+
# Convenience method for `make_render exp, true`
|
195
195
|
def make_render_in_view exp
|
196
196
|
make_render exp, true
|
197
197
|
end
|
198
198
|
|
199
|
-
#Generates :render node from call to render.
|
200
|
-
def make_render exp, in_view = false
|
199
|
+
# Generates :render node from call to render.
|
200
|
+
def make_render exp, in_view = false
|
201
201
|
render_type, value, rest = find_render_type exp, in_view
|
202
202
|
rest = process rest
|
203
203
|
result = Sexp.new(:render, render_type, value, rest)
|
@@ -205,13 +205,13 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
205
205
|
result
|
206
206
|
end
|
207
207
|
|
208
|
-
#Determines the type of a call to render.
|
208
|
+
# Determines the type of a call to render.
|
209
209
|
#
|
210
|
-
#Possible types are:
|
210
|
+
# Possible types are:
|
211
211
|
#:action, :default, :file, :inline, :js, :json, :nothing, :partial,
|
212
212
|
#:template, :text, :update, :xml
|
213
213
|
#
|
214
|
-
#And also :layout for inside templates
|
214
|
+
# And also :layout for inside templates
|
215
215
|
def find_render_type call, in_view = false
|
216
216
|
rest = Sexp.new(:hash)
|
217
217
|
type = nil
|
@@ -219,10 +219,10 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
219
219
|
first_arg = call.first_arg
|
220
220
|
|
221
221
|
if call.second_arg.nil? and first_arg == Sexp.new(:lit, :update)
|
222
|
-
return :update, nil, Sexp.new(:arglist, *call.args[0..-2]) #TODO HUH?
|
222
|
+
return :update, nil, Sexp.new(:arglist, *call.args[0..-2]) # TODO HUH?
|
223
223
|
end
|
224
224
|
|
225
|
-
#Look for render :action, ... or render "action", ...
|
225
|
+
# Look for render :action, ... or render "action", ...
|
226
226
|
if string? first_arg or symbol? first_arg
|
227
227
|
if @current_template and @tracker.options[:rails3]
|
228
228
|
type = :partial
|
@@ -234,7 +234,7 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
234
234
|
elsif first_arg.is_a? Symbol or first_arg.is_a? String
|
235
235
|
type = :action
|
236
236
|
value = Sexp.new(:lit, first_arg.to_sym)
|
237
|
-
|
237
|
+
elsif first_arg.nil?
|
238
238
|
type = :default
|
239
239
|
elsif not hash? first_arg
|
240
240
|
type = :action
|
@@ -243,21 +243,21 @@ class Railroader::BaseProcessor < Railroader::SexpProcessor
|
|
243
243
|
|
244
244
|
types_in_hash = Set[:action, :file, :inline, :js, :json, :nothing, :partial, :template, :text, :update, :xml]
|
245
245
|
|
246
|
-
#render :layout => "blah" means something else when in a template
|
246
|
+
# render :layout => "blah" means something else when in a template
|
247
247
|
if in_view
|
248
248
|
types_in_hash << :layout
|
249
249
|
end
|
250
250
|
|
251
251
|
last_arg = call.last_arg
|
252
252
|
|
253
|
-
#Look for "type" of render in options hash
|
254
|
-
#For example, render :file => "blah"
|
253
|
+
# Look for "type" of render in options hash
|
254
|
+
# For example, render :file => "blah"
|
255
255
|
if hash? last_arg
|
256
256
|
hash_iterate(last_arg) do |key, val|
|
257
257
|
if symbol? key and types_in_hash.include? key.value
|
258
258
|
type = key.value
|
259
259
|
value = val
|
260
|
-
else
|
260
|
+
else
|
261
261
|
rest << key << val
|
262
262
|
end
|
263
263
|
end
|