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_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION
Instance Method Summary
collapse
Methods included from Util
#array?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #node_type?, #number?, #params?, #pluralize, #regexp?, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #true?, #truncate_table, #underscore
Instance Method Details
Copies exp
and then formats it.
12
13
14
|
# File 'lib/brakeman/processors/output_processor.rb', line 12
def format exp
process(exp.deep_clone) || "[Format Error]"
end
|
#process(exp) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/brakeman/processors/output_processor.rb', line 18
def process exp
begin
super exp if sexp? exp and not exp.empty?
rescue Exception => e
Brakeman.debug "While formatting #{exp}: #{e}\n#{e.backtrace.join("\n")}"
end
end
|
#process_call_with_block(exp) ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/brakeman/processors/output_processor.rb', line 101
def process_call_with_block exp
call = process exp[0]
block = process exp[1] if exp[1]
out = "#{call} do\n #{block}\n end"
exp.clear
out
end
|
#process_const(exp) ⇒ Object
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/brakeman/processors/output_processor.rb', line 174
def process_const exp
if exp[0] == Brakeman::Tracker::UNKNOWN_MODEL
exp.clear
"(Unresolved Model)"
else
out = exp[0].to_s
exp.clear
out
end
end
|
#process_cookies(exp) ⇒ Object
47
48
49
50
|
# File 'lib/brakeman/processors/output_processor.rb', line 47
def process_cookies exp
exp.clear
"cookies"
end
|
#process_dxstr(exp) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/brakeman/processors/output_processor.rb', line 73
def process_dxstr exp
out = "`"
out << exp.map! do |e|
if e.is_a? String
e
elsif string? e
e[1]
else
process e
end
end.join
exp.clear
out << "`"
end
|
#process_escaped_output(exp) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/brakeman/processors/output_processor.rb', line 125
def process_escaped_output exp
out = if exp[0].node_type == :str
""
else
res = process exp[0]
if res == ""
""
else
"[Escaped Output] #{res}"
end
end
exp.clear
out
end
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/brakeman/processors/output_processor.rb', line 142
def process_format exp
out = if exp[0].node_type == :str or exp[0].node_type == :ignore
""
else
res = process exp[0]
if res == ""
""
else
"[Format] #{res}"
end
end
exp.clear
out
end
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/brakeman/processors/output_processor.rb', line 158
def process_format_escaped exp
out = if exp[0].node_type == :str or exp[0].node_type == :ignore
""
else
res = process exp[0]
if res == ""
""
else
"[Escaped] #{res}"
end
end
exp.clear
out
end
|
#process_ignore(exp) ⇒ Object
32
33
34
35
|
# File 'lib/brakeman/processors/output_processor.rb', line 32
def process_ignore exp
exp.clear
"[ignored]"
end
|
#process_lvar(exp) ⇒ Object
26
27
28
29
30
|
# File 'lib/brakeman/processors/output_processor.rb', line 26
def process_lvar exp
out = "(local #{exp[0]})"
exp.clear
out
end
|
#process_output(exp) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/brakeman/processors/output_processor.rb', line 109
def process_output exp
out = if exp[0].node_type == :str
""
else
res = process exp[0]
if res == ""
""
else
"[Output] #{res}"
end
end
exp.clear
out
end
|
#process_params(exp) ⇒ Object
37
38
39
40
|
# File 'lib/brakeman/processors/output_processor.rb', line 37
def process_params exp
exp.clear
"params"
end
|
#process_render(exp) ⇒ Object
185
186
187
188
189
190
191
|
# File 'lib/brakeman/processors/output_processor.rb', line 185
def process_render exp
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]})"
exp.clear
out
end
|
#process_rlist(exp) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/brakeman/processors/output_processor.rb', line 88
def process_rlist exp
out = exp.map do |e|
res = process e
if res == ""
nil
else
res
end
end.compact.join("\n")
exp.clear
out
end
|
#process_session(exp) ⇒ Object
42
43
44
45
|
# File 'lib/brakeman/processors/output_processor.rb', line 42
def process_session exp
exp.clear
"session"
end
|
#process_string_eval(exp) ⇒ Object
67
68
69
70
71
|
# File 'lib/brakeman/processors/output_processor.rb', line 67
def process_string_eval exp
out = "\#{#{process(exp[0])}}"
exp.clear
out
end
|
#process_string_interp(exp) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/brakeman/processors/output_processor.rb', line 52
def process_string_interp exp
out = '"'
exp.each do |e|
if e.is_a? String
out << e
else
res = process e
out << res unless res == ""
end
end
out << '"'
exp.clear
out
end
|
#util_dthing(type, exp) ⇒ Object
This is copied from Ruby2Ruby, except the :string_eval type has been added
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/brakeman/processors/output_processor.rb', line 194
def util_dthing(type, exp)
s = []
s << dthing_escape(type, exp.shift)
until exp.empty?
pt = exp.shift
case pt
when Sexp then
case pt.first
when :str then
s << dthing_escape(type, pt.last)
when :evstr, :string_eval then
s << '#{' << process(pt) << '}' else
raise "unknown type: #{pt.inspect}"
end
else
end
end
s.join
end
|