summaryrefslogtreecommitdiff
path: root/lib/yesno.c
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2015-03-24 12:15:27 +0000
committerPádraig Brady <P@draigBrady.com>2015-03-24 12:33:12 +0000
commit386315b3057802aa426b0599db86e8462cbd34e2 (patch)
tree6718b6664bed89406b82fbc6f6bb4fb52bba38d8 /lib/yesno.c
parentd164bf67cc2d471facdd5d3b09f80f3688b3a21b (diff)
downloadgnulib-386315b3057802aa426b0599db86e8462cbd34e2.tar.gz
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).
Diffstat (limited to 'lib/yesno.c')
-rw-r--r--lib/yesno.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/yesno.c b/lib/yesno.c
index d5d9eec5ce..331a40833a 100644
--- a/lib/yesno.c
+++ b/lib/yesno.c
@@ -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));
}