mirror of
https://https.git.savannah.gnu.org/git/gnulib.git
synced 2026-09-01 02:34:55 +00:00
yesno: make EOL optional in ENABLE_NLS case also
yesno behaves differently in a corner case depending on ENABLE_NLS. With an input of "y" followed by an EOF the input is considered to be "no", because the last character is replaced with '\0'. It was assumed that there is a newline, which doesn't have to be true. If ENABLE_NLS is not set, getchar() reads y and accepts it as "yes", looping through more getchar() calls until reaching newline or EOF. * lib/yesno.c (yesno): Check for EOL before replacing. * tests/test-yesno.sh: Add a test case (test along with gettext).
This commit is contained in:
committed by
Pádraig Brady
parent
d164bf67cc
commit
386315b305
@@ -1,3 +1,9 @@
|
||||
2015-03-24 Tobias Stoeckmann <tobias@stoeckmann.org>
|
||||
|
||||
yesno: make EOL optional in ENABLE_NLS case also (trival)
|
||||
* lib/yesno.c (yesno): Check for EOL before replacing.
|
||||
* tests/test-yesno.sh: Add a test case (test along with gettext).
|
||||
|
||||
2015-03-22 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
fdopendir-tests: test it does not close its arg
|
||||
|
||||
+4
-1
@@ -42,7 +42,10 @@ yesno (void)
|
||||
yes = false;
|
||||
else
|
||||
{
|
||||
response[response_len - 1] = '\0';
|
||||
/* Remove EOL if present as that's not part of the matched response,
|
||||
and not matched by $ for example. */
|
||||
if (response[response_len - 1] == '\n')
|
||||
response[response_len - 1] = '\0';
|
||||
yes = (0 < rpmatch (response));
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,14 @@ echo yes | test-yesno 2 > out1.tmp || fail=1
|
||||
LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
|
||||
cmp xout.tmp out.tmp || fail=1
|
||||
|
||||
# Test for behavior with no EOL at EOF
|
||||
cat <<EOF > xout.tmp
|
||||
Y
|
||||
EOF
|
||||
printf y | test-yesno 1 > out1.tmp || fail=1
|
||||
LC_ALL=C tr -d "$cr" < out1.tmp > out.tmp || fail=1
|
||||
cmp xout.tmp out.tmp || fail=1
|
||||
|
||||
# Test for behavior on EOF
|
||||
cat <<EOF > xout.tmp
|
||||
N
|
||||
|
||||
Reference in New Issue
Block a user