From dff5de66da755a3413b11e136ee1012d8b43c026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Wed, 19 Mar 2025 16:26:45 +0100 Subject: [PATCH] fix redirection parsing sometimes skipping over redirections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This happens when multiple redirections are following each others, such as in echo hi > out < in which would be parsed as ╰─ t_cmdgroup ├─ t_cmdlist │ ├─ num_cmds = 1 │ ╰─ cmd[0] │ ├─ t_cmdlist_item │ │ ╰─ t_pipeline │ │ ├─ num_cmd = 1 │ │ ╰─ cmd[0] │ │ ╰─ t_simple_cmd │ │ ├─ words = [echo][hi][<][in] │ │ ╰─ t_redir_list │ │ ╰─ redirection[0] │ │ ╰─ t_redirection │ │ ├─ t_redir_type = REDIR_OUTPUT │ │ ╰─ marker = [out] │ ╰─ t_operator = END ╰─ (no redirections) when the correct parsing is ╰─ t_cmdgroup ├─ t_cmdlist │ ├─ num_cmds = 1 │ ╰─ cmd[0] │ ├─ t_cmdlist_item │ │ ╰─ t_pipeline │ │ ├─ num_cmd = 1 │ │ ╰─ cmd[0] │ │ ╰─ t_simple_cmd │ │ ├─ words = [echo][hi] │ │ ╰─ t_redir_list │ │ ├─ redirection[0] │ │ │ ╰─ t_redirection │ │ │ ├─ t_redir_type = REDIR_OUTPUT │ │ │ ╰─ marker = [out] │ │ ╰─ redirection[1] │ │ ╰─ t_redirection │ │ ├─ t_redir_type = REDIR_INPUT │ │ ╰─ marker = [in] │ ╰─ t_operator = END ╰─ (no redirections) --- .../redirections/redirection_parsing.c | 7 +- test.sh | 66 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/postprocess/redirections/redirection_parsing.c b/src/postprocess/redirections/redirection_parsing.c index 78962e4..e7a8fbb 100644 --- a/src/postprocess/redirections/redirection_parsing.c +++ b/src/postprocess/redirections/redirection_parsing.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/07 12:30:04 by khais #+# #+# */ -/* Updated: 2025/03/11 14:58:11 by khais ### ########.fr */ +/* Updated: 2025/03/19 18:28:28 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,9 +78,12 @@ struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd) { type = redir_type_from_worddesc(wordlist_get(cmd->words, i)); if (type != REDIR_INVALID) + { if (redirection_found(cmd, i, type) == NULL) return (NULL); - i++; + } + else + i++; } return (cmd); } diff --git a/test.sh b/test.sh index 9957795..8bbbcbb 100755 --- a/test.sh +++ b/test.sh @@ -102,6 +102,29 @@ expecting <outfile +EOF +expecting < out EOF @@ -119,8 +142,51 @@ expecting <outfile there < infile < infile2 >> append +EOF +expecting <