Skip to content

Commit efba300

Browse files
committed
Fix early returns in Reline prompt
1 parent 488d4c0 commit efba300

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/rex/post/sql/ui/console/interactive_sql_client.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,24 @@ def _multiline
8080

8181
finished = false
8282
begin
83+
result = nil
8384
prompt_proc_before = ::Reline.prompt_proc
8485
::Reline.prompt_proc = proc { |line_buffer| line_buffer.each_with_index.map { |_line, i| i > 0 ? 'SQL *> ' : 'SQL >> ' } }
8586

8687
# We want to do this in a loop
8788
# multiline_input is the whole string that the user has input, not just the current line.
8889
raw_query = ::Reline.readmultiline('SQL >> ', use_history = true) do |multiline_input|
8990
# The user pressed ctrl + c or ctrl + z and wants to background our SQL prompt
90-
return { status: :exit, result: nil } unless self.interacting
91+
unless self.interacting
92+
result = { status: :exit, result: nil }
93+
next true
94+
end
95+
9196
# When the user has pressed the enter key with no input, don't run any queries;
9297
# simply give them a new prompt on a new line.
9398
if multiline_input.chomp.empty?
94-
print_blank_line
95-
return { status: :success, result: nil }
99+
result = { status: :success, result: nil }
100+
next true
96101
end
97102

98103
# In the case only a stop word was input, exit out of the REPL shell
@@ -106,6 +111,10 @@ def _multiline
106111
::Reline.prompt_proc = prompt_proc_before
107112
end
108113

114+
if result
115+
return result
116+
end
117+
109118
if finished
110119
self.interacting = false
111120
print_status 'Exiting Shell mode.'

0 commit comments

Comments
 (0)