/usr/lib/ruby/vendor_ruby/web_console/evaluator.rb is in ruby-web-console 2.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | module WebConsole
# Simple Ruby code evaluator.
#
# This class wraps a +Binding+ object and evaluates code inside of it. The
# difference of a regular +Binding+ eval is that +Evaluator+ will always
# return a string and will format exception output.
class Evaluator
# Cleanses exceptions raised inside #eval.
cattr_reader :cleaner
@@cleaner = ActiveSupport::BacktraceCleaner.new
@@cleaner.add_silencer { |line| line.start_with?(File.expand_path('..', __FILE__)) }
def initialize(binding = TOPLEVEL_BINDING)
@binding = binding
end
def eval(input)
"=> #{@binding.eval(input).inspect}\n"
rescue Exception => exc
format_exception(exc)
end
private
def format_exception(exc)
backtrace = cleaner.clean(Array(exc.backtrace) - caller)
format = "#{exc.class.name}: #{exc}\n"
format << backtrace.map { |trace| "\tfrom #{trace}\n" }.join
format
end
end
end
|