diff --git a/jruby/lib/io/console/common.rb b/jruby/lib/io/console/common.rb index 9252bd9..a6d550c 100644 --- a/jruby/lib/io/console/common.rb +++ b/jruby/lib/io/console/common.rb @@ -64,7 +64,7 @@ def getpass(prompt = nil) ensure puts($/) end - str.chomp + str&.chomp end def input_pending? @@ -162,7 +162,7 @@ def getch(*) def getpass(prompt = nil) write(prompt) if prompt - str = gets.chomp + str = gets&.chomp puts($/) str end diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb index 48743fc..a224de2 100644 --- a/test/io/console/test_io_console.rb +++ b/test/io/console/test_io_console.rb @@ -367,6 +367,17 @@ def test_getpass end end + def test_getpass_empty + helper do |m, s| + result = Thread.new {s.getpass("> ")} + assert_equal("> ", m.readpartial(10)) + Timeout.timeout(1) {Thread.pass while s.echo?} + m.write "\C-D" + assert_nil(result.value) + assert_equal("\r\n", m.readpartial(10)) + end + end + def test_iflush pend "stty cannot flush terminal queues" if IO.private_method_defined?(:_io_console_stty)