Skip to content

Commit 26214cb

Browse files
authored
Land rapid7#18889, Fresh SQL prompt when pressing enter if no input was provided
2 parents 4b54d43 + efba300 commit 26214cb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,25 @@ 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
88+
# multiline_input is the whole string that the user has input, not just the current line.
8789
raw_query = ::Reline.readmultiline('SQL >> ', use_history = true) do |multiline_input|
8890
# The user pressed ctrl + c or ctrl + z and wants to background our SQL prompt
89-
return { status: :exit, result: nil } unless self.interacting
91+
unless self.interacting
92+
result = { status: :exit, result: nil }
93+
next true
94+
end
95+
96+
# When the user has pressed the enter key with no input, don't run any queries;
97+
# simply give them a new prompt on a new line.
98+
if multiline_input.chomp.empty?
99+
result = { status: :success, result: nil }
100+
next true
101+
end
90102

91103
# In the case only a stop word was input, exit out of the REPL shell
92104
finished = (multiline_input.split.count == 1 && stop_words.include?(multiline_input.split.last))
@@ -99,6 +111,10 @@ def _multiline
99111
::Reline.prompt_proc = prompt_proc_before
100112
end
101113

114+
if result
115+
return result
116+
end
117+
102118
if finished
103119
self.interacting = false
104120
print_status 'Exiting Shell mode.'

0 commit comments

Comments
 (0)