From 4d59d9cfb5fe97e422846a1050a785f1e78b23d8 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Sat, 26 Aug 2023 13:44:25 +0200 Subject: [PATCH] Also allow `command and` in a pipeline Similar to `time`, except that one is more common as a command. Note that this will also allow `builtin and`, which is somewhat useless, but then it is also useless outside of a pipeline. Addition to #9985 (cherry picked from commit b454b3bc40a2af3cf4a3034007c06a6d2a998f35) --- src/parse_util.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/parse_util.cpp b/src/parse_util.cpp index ea55eca5f..943e3131b 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -1155,23 +1155,23 @@ static bool detect_errors_in_decorated_statement(const wcstring &buff_src, // beginning. We can't disallow them as commands entirely because we need to support 'and // --help', etc. if (pipe_pos == pipeline_position_t::subsequent) { - // check if our command is 'and' or 'or'. This is very clumsy; we don't catch e.g. quoted - // commands. - const wcstring &command = dst.command.source(buff_src, storage); - if (command == L"and" || command == L"or") { - errored = append_syntax_error(parse_errors, source_start, source_length, - INVALID_PIPELINE_CMD_ERR_MSG, command.c_str()); - } + // We only reject it if we have no decoration. + // `echo foo | command time something` + // is entirely fair and valid. + // Other current decorations like "exec" + // are already forbidden. + const auto &deco = dst.decoration(); + if (deco == statement_decoration_t::none) { + // check if our command is 'and' or 'or'. This is very clumsy; we don't catch e.g. quoted + // commands. + const wcstring &command = dst.command.source(buff_src, storage); + if (command == L"and" || command == L"or") { + errored = append_syntax_error(parse_errors, source_start, source_length, + INVALID_PIPELINE_CMD_ERR_MSG, command.c_str()); + } - // Similarly for time (#8841). - if (command == L"time") { - // We only reject it if we have no decoration. - // `echo foo | command time something` - // is entirely fair and valid. - // Other current decorations like "exec" - // are already forbidden. - const auto &deco = dst.decoration(); - if (deco == statement_decoration_t::none) { + // Similarly for time (#8841). + if (command == L"time") { errored = append_syntax_error(parse_errors, source_start, source_length, TIME_IN_PIPELINE_ERR_MSG); }