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).
+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
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));
}
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