diff --git a/lib/rex/ui/text/shell/history_manager.rb b/lib/rex/ui/text/shell/history_manager.rb index c974b4e1344d2..6cf926168be3b 100644 --- a/lib/rex/ui/text/shell/history_manager.rb +++ b/lib/rex/ui/text/shell/history_manager.rb @@ -28,8 +28,8 @@ def initialize # @param [Proc] block # @return [nil] def with_context(history_file: nil, name: nil, input_library: nil, &block) - input_library ||= :readline # Default to Readline for backwards compatibility. - push_context(history_file: history_file, name: name, input_library: input_library) + # Default to Readline for backwards compatibility. + push_context(history_file: history_file, name: name, input_library: input_library || :readline) begin block.call @@ -69,7 +69,7 @@ def debug? def push_context(history_file: nil, name: nil, input_library: nil) $stderr.puts("Push context before\n#{JSON.pretty_generate(_contexts)}") if debug? - new_context = { history_file: history_file, name: name, input_library: input_library } + new_context = { history_file: history_file, name: name, input_library: input_library || :readline } switch_context(new_context, @contexts.last) @contexts.push(new_context) diff --git a/spec/lib/rex/ui/text/shell/history_manager_spec.rb b/spec/lib/rex/ui/text/shell/history_manager_spec.rb index 90fe4c802d2e9..e4775fecc58e8 100644 --- a/spec/lib/rex/ui/text/shell/history_manager_spec.rb +++ b/spec/lib/rex/ui/text/shell/history_manager_spec.rb @@ -25,7 +25,7 @@ (expect do |block| subject.with_context(name: 'a') do expected_contexts = [ - { history_file: nil, name: 'a' }, + { history_file: nil, input_library: :readline, name: 'a' }, ] expect(subject._contexts).to eq(expected_contexts) block.to_proc.call @@ -36,7 +36,7 @@ context 'when there is an existing stack' do before(:each) do - subject.send(:push_context, history_file: nil, name: 'a') + subject.send(:push_context, history_file: nil, input_library: :readline, name: 'a') end it 'continues to have the previous existing stack' do @@ -44,7 +44,7 @@ # noop } expected_contexts = [ - { history_file: nil, name: 'a' }, + { history_file: nil, input_library: :readline, name: 'a' }, ] expect(subject._contexts).to eq(expected_contexts) end @@ -53,8 +53,8 @@ (expect do |block| subject.with_context(name: 'b') do expected_contexts = [ - { history_file: nil, name: 'a' }, - { history_file: nil, name: 'b' }, + { history_file: nil, input_library: :readline, name: 'a' }, + { history_file: nil, input_library: :readline, name: 'b' }, ] expect(subject._contexts).to eq(expected_contexts) block.to_proc.call @@ -69,7 +69,7 @@ } end.to raise_exception ArgumentError, 'Mock error' expected_contexts = [ - { history_file: nil, name: 'a' }, + { history_file: nil, input_library: :readline, name: 'a' }, ] expect(subject._contexts).to eq(expected_contexts) end @@ -79,9 +79,9 @@ describe '#push_context' do context 'when the stack is empty' do it 'stores the history contexts' do - subject.send(:push_context, history_file: nil, name: 'a') + subject.send(:push_context, history_file: nil, input_library: :readline, name: 'a') expected_contexts = [ - { history_file: nil, name: 'a' } + { history_file: nil, input_library: :readline, name: 'a' } ] expect(subject._contexts).to eq(expected_contexts) end @@ -90,12 +90,12 @@ context 'when multiple values are pushed' do it 'stores the history contexts' do subject.send(:push_context, history_file: nil, name: 'a') - subject.send(:push_context, history_file: nil, name: 'b') - subject.send(:push_context, history_file: nil, name: 'c') + subject.send(:push_context, history_file: nil, input_library: :readline, name: 'b') + subject.send(:push_context, history_file: nil, input_library: :reline, name: 'c') expected_contexts = [ - { history_file: nil, name: 'a' }, - { history_file: nil, name: 'b' }, - { history_file: nil, name: 'c' }, + { history_file: nil, input_library: :readline, name: 'a' }, + { history_file: nil, input_library: :readline, name: 'b' }, + { history_file: nil, input_library: :reline, name: 'c' }, ] expect(subject._contexts).to eq(expected_contexts) end @@ -113,12 +113,12 @@ end context 'when the stack is not empty' do - it 'continues to have an empty stack' do + it 'continues to have a non-empty stack' do subject.send(:push_context, history_file: nil, name: 'a') subject.send(:push_context, history_file: nil, name: 'b') subject.send(:pop_context) expected_contexts = [ - { history_file: nil, name: 'a' }, + { history_file: nil, input_library: :readline, name: 'a' }, ] expect(subject._contexts).to eq(expected_contexts) end