Skip to content

Commit

Permalink
Fix early returns in Reline prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 committed Feb 27, 2024
1 parent 488d4c0 commit efba300
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/rex/post/sql/ui/console/interactive_sql_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,24 @@ def _multiline

finished = false
begin
result = nil
prompt_proc_before = ::Reline.prompt_proc
::Reline.prompt_proc = proc { |line_buffer| line_buffer.each_with_index.map { |_line, i| i > 0 ? 'SQL *> ' : 'SQL >> ' } }

# We want to do this in a loop
# multiline_input is the whole string that the user has input, not just the current line.
raw_query = ::Reline.readmultiline('SQL >> ', use_history = true) do |multiline_input|
# The user pressed ctrl + c or ctrl + z and wants to background our SQL prompt
return { status: :exit, result: nil } unless self.interacting
unless self.interacting
result = { status: :exit, result: nil }
next true
end

# When the user has pressed the enter key with no input, don't run any queries;
# simply give them a new prompt on a new line.
if multiline_input.chomp.empty?
print_blank_line
return { status: :success, result: nil }
result = { status: :success, result: nil }
next true
end

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

if result
return result
end

if finished
self.interacting = false
print_status 'Exiting Shell mode.'
Expand Down

0 comments on commit efba300

Please sign in to comment.