summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-08-18 11:46:04 +0900
committergit <svn-admin@ruby-lang.org>2023-08-18 03:55:04 +0000
commitcff8058701641c680de4924ea98d1b9d0efd9244 (patch)
treef5639e76056fc3e7093dc30cfe1abd4253216916 /ext
parent528da4347cb68d2e19373b3d0e517ec7d0d1ea90 (diff)
[ruby/io-console] Ensure to put a newline after password
https://github.com/ruby/io-console/commit/15e36af171
Diffstat (limited to 'ext')
-rw-r--r--ext/io/console/console.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index da50fc6922..dd15c8b015 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -1539,6 +1539,12 @@ puts_call(VALUE io)
}
static VALUE
+gets_call(VALUE io)
+{
+ return rb_funcallv(io, id_gets, 0, 0);
+}
+
+static VALUE
getpass_call(VALUE io)
{
return ttymode(io, rb_io_gets, io, set_noecho, NULL);
@@ -1610,9 +1616,8 @@ io_getpass(int argc, VALUE *argv, VALUE io)
rb_check_arity(argc, 0, 1);
prompt(argc, argv, io);
rb_check_funcall(io, id_flush, 0, 0);
- str = str_chomp(rb_funcallv(io, id_gets, 0, 0));
- puts_call(io);
- return str;
+ str = rb_ensure(gets_call, io, puts_call, io);
+ return str_chomp(str);
}
/*