Class: Brakeman::OutputProcessor
- Inherits:
-
Ruby2Ruby
- Object
- Ruby2Ruby
- Brakeman::OutputProcessor
show all
- Includes:
- Util
- Defined in:
- lib/brakeman/processors/output_processor.rb
Overview
Produces formatted output strings from Sexps. Recommended usage is
OutputProcessor.new.format(Sexp.new(:str, "hello"))
Constant Summary
Constants included
from Util
Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::DIR_CONST, Util::LITERALS, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::REQUEST_REQUEST_PARAMETERS, Util::SAFE_LITERAL, Util::SESSION, Util::SESSION_SEXP, Util::SIMPLE_LITERALS
Instance Method Summary
collapse
Methods included from Util
#all_literals?, #array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #dir_glob?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #hash_values, #integer?, #kwsplat?, #literal?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #recurse_check?, #regexp?, #remove_kwsplat, #request_env?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #simple_literal?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore
Constructor Details
Returns a new instance of OutputProcessor.
11
12
13
14
|
# File 'lib/brakeman/processors/output_processor.rb', line 11
def initialize *args
super
@user_input = nil
end
|
Instance Method Details
Copies exp
and then formats it.
17
18
19
20
21
|
# File 'lib/brakeman/processors/output_processor.rb', line 17
def format exp, user_input = nil, &block
@user_input = user_input
@user_input_block = block
process(exp.deep_clone) || "[Format Error]"
end
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/brakeman/processors/output_processor.rb', line 114
def output_format exp, tag
out = if exp[1].node_type == :str or exp[1].node_type == :ignore
""
else
res = process exp[1]
if res == ""
""
else
"[#{tag}] #{res}"
end
end
out
end
|
#process(exp) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/brakeman/processors/output_processor.rb', line 25
def process exp
begin
if @user_input and @user_input == exp
@user_input_block.call(exp, super(exp))
else
super exp if sexp? exp and not exp.empty?
end
rescue => e
Brakeman.debug "While formatting #{exp}: #{e}\n#{e.backtrace.join("\n")}"
end
end
|
#process_const(exp) ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'lib/brakeman/processors/output_processor.rb', line 130
def process_const exp
if exp[1] == Brakeman::Tracker::UNKNOWN_MODEL
"(Unresolved Model)"
else
out = exp[1].to_s
out
end
end
|
#process_cookies(exp) ⇒ Object
49
50
51
|
# File 'lib/brakeman/processors/output_processor.rb', line 49
def process_cookies exp
"cookies"
end
|
#process_defn(exp) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/brakeman/processors/output_processor.rb', line 66
def process_defn exp
exp = exp.deep_clone
exp.shift
name = exp.shift
args = process exp.shift
args = "" if args == "()"
exp.shift if exp == s(s(:nil))
body = []
until exp.empty? do
body << indent(process(exp.shift))
end
body << indent("# do nothing") if body.empty?
body = body.join("\n")
return "def #{name}#{args}\n#{body}\nend".gsub(/\n\s*\n+/, "\n")
end
|
#process_escaped_output(exp) ⇒ Object
101
102
103
|
# File 'lib/brakeman/processors/output_processor.rb', line 101
def process_escaped_output exp
output_format exp, "Escaped Output"
end
|
106
107
108
|
# File 'lib/brakeman/processors/output_processor.rb', line 106
def process_format exp
output_format exp, "Format"
end
|
110
111
112
|
# File 'lib/brakeman/processors/output_processor.rb', line 110
def process_format_escaped exp
output_format exp, "Escaped"
end
|
#process_ignore(exp) ⇒ Object
37
38
39
|
# File 'lib/brakeman/processors/output_processor.rb', line 37
def process_ignore exp
"[ignored]"
end
|
#process_iter(exp) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/brakeman/processors/output_processor.rb', line 89
def process_iter exp
call = process exp[1]
block = process_rlist exp.sexp_body(3)
out = "#{call} do\n #{block}\n end"
out
end
|
#process_output(exp) ⇒ Object
97
98
99
|
# File 'lib/brakeman/processors/output_processor.rb', line 97
def process_output exp
output_format exp, "Output"
end
|
#process_params(exp) ⇒ Object
41
42
43
|
# File 'lib/brakeman/processors/output_processor.rb', line 41
def process_params exp
"params"
end
|
#process_render(exp) ⇒ Object
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/brakeman/processors/output_processor.rb', line 139
def process_render exp
exp = exp.deep_clone
exp.shift
exp[1] = process exp[1] if sexp? exp[1]
exp[2] = process exp[2] if sexp? exp[2]
out = "render(#{exp[0]} => #{exp[1]}, #{exp[2]})"
out
end
|
#process_rlist(exp) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/brakeman/processors/output_processor.rb', line 53
def process_rlist exp
out = exp.map do |e|
res = process e
if res == ""
nil
else
res
end
end.compact.join("\n")
out
end
|
#process_session(exp) ⇒ Object
45
46
47
|
# File 'lib/brakeman/processors/output_processor.rb', line 45
def process_session exp
"session"
end
|