Stop ignoring initial command in read -c

`read` allows specifying the initial command line text. This was
text got accidentally ignored starting in a32248277f. Fix this
regression and add a test.

Fixes #8633
This commit is contained in:
ridiculousfish 2022-01-16 13:34:45 -08:00
parent 49a0362c12
commit 1f8ce5ff6c
2 changed files with 18 additions and 1 deletions

View file

@ -4189,7 +4189,12 @@ bool reader_data_t::jump(jump_direction_t dir, jump_precision_t precision, edita
return success;
}
maybe_t<wcstring> reader_readline(int nchars) { return current_data()->readline(nchars); }
maybe_t<wcstring> reader_readline(int nchars) {
auto *data = current_data();
// Apply any outstanding commandline changes (#8633).
data->apply_commandline_state_changes();
return data->readline(nchars);
}
int reader_reading_interrupted() {
int res = reader_test_and_clear_interrupted();

View file

@ -54,6 +54,18 @@ expect_prompt()
expect_marker(2)
print_var_contents("foo", "bar")
# read -c (see #8633)
sendline(r"read -c init_text somevar && echo $somevar")
expect_re("\r\n?read> init_text$")
sendline("someval")
expect_prompt("someval\r\n")
sendline(r"read --command='some other text' somevar && echo $somevar")
expect_re("\r\n?read> some other text$")
sendline("another value")
expect_prompt("another value\r\n")
# read -s
sendline("read -s foo")