Skip to content

Commit 9acae80

Browse files
kraviiNihalJain
andauthored
HBASE-28250 Bump jruby to 9.4.8.0 to fix snakeyaml CVE (apache#6127) (apache#6146) (#23)
* Sync code as per irb 1.4.2 * Also provide option to try irb's new functionalities for colorize and autocomplete Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Nick Dimiduk <ndimiduk@apache.org> (cherry picked from commit 6788ff4) Co-authored-by: Nihal Jain <nihaljain@apache.org>
1 parent 08cacb4 commit 9acae80

3 files changed

Lines changed: 63 additions & 49 deletions

File tree

hbase-shell/src/main/ruby/irb/hirb.rb

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,21 @@ def initialize(workspace = nil, interactive = true, input_method = nil)
5353
$stdout = STDOUT
5454
end
5555

56-
def output_value
56+
def output_value(omit = false)
5757
# Suppress output if last_value is 'nil'
5858
# Otherwise, when user types help, get ugly 'nil'
5959
# after all output.
60-
super unless @context.last_value.nil?
60+
super(omit) unless @context.last_value.nil?
6161
end
6262

63-
# Copied from irb.rb and overrides the rescue Exception block so the
63+
# Copied from https://github.com/ruby/irb/blob/v1.4.2/lib/irb.rb
64+
# We override the rescue Exception block so the
6465
# Shell::exception_handler can deal with the exceptions.
6566
def eval_input
67+
exc = nil
68+
6669
@scanner.set_prompt do
67-
|ltype, indent, continue, line_no|
70+
|ltype, indent, continue, line_no|
6871
if ltype
6972
f = @context.prompt_s
7073
elsif continue
@@ -80,17 +83,19 @@ def eval_input
8083
else
8184
@context.io.prompt = p = ""
8285
end
83-
if @context.auto_indent_mode
86+
if @context.auto_indent_mode and !@context.io.respond_to?(:auto_indent)
8487
unless ltype
85-
ind = prompt(@context.prompt_i, ltype, indent, line_no)[/.*\z/].size +
88+
prompt_i = @context.prompt_i.nil? ? "" : @context.prompt_i
89+
ind = prompt(prompt_i, ltype, indent, line_no)[/.*\z/].size +
8690
indent * 2 - p.size
8791
ind += 2 if continue
8892
@context.io.prompt = p + " " * ind if ind > 0
8993
end
9094
end
95+
@context.io.prompt
9196
end
9297

93-
@scanner.set_input(@context.io) do
98+
@scanner.set_input(@context.io, context: @context) do
9499
signal_status(:IN_INPUT) do
95100
if l = @context.io.gets
96101
print l if @context.verbose?
@@ -101,24 +106,51 @@ def eval_input
101106
printf "Use \"exit\" to leave %s\n", @context.ap_name
102107
end
103108
else
104-
print "\n"
109+
print "\n" if @context.prompting?
105110
end
106111
end
107112
l
108113
end
109114
end
110115

116+
@scanner.set_auto_indent(@context) if @context.auto_indent_mode
117+
111118
@scanner.each_top_level_statement do |line, line_no|
112119
signal_status(:IN_EVAL) do
113120
begin
114-
line.untaint
115-
@context.evaluate(line, line_no)
116-
output_value if @context.echo?
117-
exc = nil
121+
line.untaint if RUBY_VERSION < '2.7'
122+
if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty?
123+
IRB.set_measure_callback
124+
end
125+
if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty?
126+
result = nil
127+
last_proc = proc{ result = @context.evaluate(line, line_no, exception: exc) }
128+
IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) { |chain, item|
129+
_name, callback, arg = item
130+
proc {
131+
callback.(@context, line, line_no, arg, exception: exc) do
132+
chain.call
133+
end
134+
}
135+
}.call
136+
@context.set_last_value(result)
137+
else
138+
@context.evaluate(line, line_no, exception: exc)
139+
end
140+
if @context.echo?
141+
if assignment_expression?(line)
142+
if @context.echo_on_assignment?
143+
output_value(@context.echo_on_assignment? == :truncate)
144+
end
145+
else
146+
output_value
147+
end
148+
end
118149
rescue Interrupt => exc
119150
rescue SystemExit, SignalException
120151
raise
121152
rescue SyntaxError => exc
153+
# HBASE-27726: Ignore SyntaxError to prevent exiting Shell on unexpected syntax.
122154
raise exc unless @interactive
123155
rescue NameError => exc
124156
raise exc unless @interactive
@@ -128,43 +160,13 @@ def eval_input
128160
# This modifies this copied method from JRuby so that the HBase shell can
129161
# manage the exception and set a proper exit code on the process.
130162
raise exc
163+
else
164+
exc = nil
165+
next
131166
end
132-
if exc
133-
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
134-
!(SyntaxError === exc)
135-
irb_bug = true
136-
else
137-
irb_bug = false
138-
end
139-
140-
messages = []
141-
lasts = []
142-
levels = 0
143-
if exc.backtrace
144-
count = 0
145-
exc.backtrace.each do |m|
146-
m = @context.workspace.filter_backtrace(m) or next unless irb_bug
147-
m = sprintf("%9d: from %s", (count += 1), m)
148-
if messages.size < @context.back_trace_limit
149-
messages.push(m)
150-
elsif lasts.size < @context.back_trace_limit
151-
lasts.push(m).shift
152-
levels += 1
153-
end
154-
end
155-
end
156-
attr = STDOUT.tty? ? ATTR_TTY : ATTR_PLAIN
157-
print "#{attr[1]}Traceback#{attr[]} (most recent call last):\n"
158-
unless lasts.empty?
159-
puts lasts.reverse
160-
printf "... %d levels...\n", levels if levels > 0
161-
end
162-
puts messages.reverse
163-
messages = exc.to_s.split(/\n/)
164-
print "#{attr[1]}#{exc.class} (#{attr[4]}#{messages.shift}#{attr[0, 1]})#{attr[]}\n"
165-
puts messages.map {|s| "#{attr[1]}#{s}#{attr[]}\n"}
166-
print "Maybe IRB bug!\n" if irb_bug
167-
end
167+
handle_exception(exc)
168+
@context.workspace.local_variable_set(:_, exc)
169+
exc = nil
168170
end
169171
end
170172
end

hbase-shell/src/main/ruby/jar-bootstrap.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
-h | --help This help.
6161
-n | --noninteractive Do not run within an IRB session and exit with non-zero
6262
status on first error.
63+
-c | --colorize Enable colorized output.
64+
-a | --autocomplete Enable auto-completion.
6365
--top-level-defs Compatibility flag to export HBase shell commands onto
6466
Ruby's main object
6567
-Dkey=value Pass hbase-*.xml Configuration overrides. For example, to
@@ -97,6 +99,8 @@ def add_to_configuration(c, arg)
9799
['--help', '-h', GetoptLong::NO_ARGUMENT],
98100
['--debug', '-d', GetoptLong::NO_ARGUMENT],
99101
['--noninteractive', '-n', GetoptLong::NO_ARGUMENT],
102+
['--colorize', '-c', GetoptLong::NO_ARGUMENT],
103+
['--autocomplete', '-a', GetoptLong::NO_ARGUMENT],
100104
['--top-level-defs', GetoptLong::NO_ARGUMENT],
101105
['-D', GetoptLong::REQUIRED_ARGUMENT],
102106
['--return-values', '-r', GetoptLong::NO_ARGUMENT]
@@ -107,6 +111,8 @@ def add_to_configuration(c, arg)
107111
log_level = 'ERROR'
108112
@shell_debug = false
109113
interactive = true
114+
colorize = false
115+
autocomplete = false
110116
full_backtrace = false
111117
top_level_definitions = false
112118

@@ -124,6 +130,10 @@ def add_to_configuration(c, arg)
124130
puts 'Setting DEBUG log level...'
125131
when '--noninteractive'
126132
interactive = false
133+
when '--colorize'
134+
colorize = true
135+
when '--autocomplete'
136+
autocomplete = true
127137
when '--return-values'
128138
warn '[INFO] the -r | --return-values option is ignored. we always behave '\
129139
'as though it was given.'
@@ -205,6 +215,8 @@ def debug?
205215
IRB.conf[:AP_NAME] = 'hbase'
206216
IRB.conf[:PROMPT_MODE] = :CUSTOM
207217
IRB.conf[:BACK_TRACE_LIMIT] = 0 unless full_backtrace
218+
IRB.conf[:USE_AUTOCOMPLETE] = autocomplete
219+
IRB.conf[:USE_COLORIZE] = colorize
208220

209221
# Create a workspace we'll use across sessions.
210222
workspace = @shell.get_workspace

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@
610610
<wx.rs.api.version>2.1.1</wx.rs.api.version>
611611
<glassfish.jsp.version>2.3.2</glassfish.jsp.version>
612612
<glassfish.el.version>3.0.1-b08</glassfish.el.version>
613-
<jruby.version>9.2.13.0</jruby.version>
613+
<jruby.version>9.4.8.0</jruby.version>
614614
<junit.version>4.13.2</junit.version>
615615
<hamcrest.version>1.3</hamcrest.version>
616616
<opentelemetry.version>1.49.0</opentelemetry.version>

0 commit comments

Comments
 (0)