From a012aedb31b4b959dfd66d6643c43564408a9f00 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 21 Sep 2014 20:00:26 -0700 Subject: [PATCH] Fix incorrect error on `read` with 1-character input When `read` is given a single character of input (including the newline), it was bailing as if it had been given no input. This is incorrect. --- builtin.cpp | 2 +- tests/read.in | 2 ++ tests/read.out | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin.cpp b/builtin.cpp index 4604190c3..e7c492859 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -2655,7 +2655,7 @@ static int builtin_read(parser_t &parser, wchar_t **argv) } } - if (buff.size() < 2 && eof) + if (buff.empty() && eof) { exit_res = 1; } diff --git a/tests/read.in b/tests/read.in index 7cf091129..893797a1b 100644 --- a/tests/read.in +++ b/tests/read.in @@ -38,6 +38,8 @@ echo 'test' | read -l one two three print_vars one two three echo 'foo bar baz' | read -l one two three print_vars one two three +echo -n 'a' | read -l one +echo "$status $one" echo set -l IFS diff --git a/tests/read.out b/tests/read.out index d8cf948d1..43b016db3 100644 --- a/tests/read.out +++ b/tests/read.out @@ -17,6 +17,7 @@ two 1 '' 1 '' 1 'test' 1 '' 1 '' 1 'foo' 1 'bar' 1 ' baz' +0 a 1 'hello' 1 'h' 1 'ello'