mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix redirection parsing sometimes skipping over redirections
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)
This commit is contained in:
parent
9fb4e13420
commit
dff5de66da
2 changed files with 71 additions and 2 deletions
66
test.sh
66
test.sh
|
|
@ -102,6 +102,29 @@ expecting <<EOF
|
|||
╰─ (no redirections)
|
||||
EOF
|
||||
|
||||
when_run <<EOF "single redirection is parsed"
|
||||
echo hello>outfile
|
||||
EOF
|
||||
expecting <<EOF
|
||||
╰─ t_cmdgroup
|
||||
├─ t_cmdlist
|
||||
│ ├─ num_cmds = 1
|
||||
│ ╰─ cmd[0]
|
||||
│ ├─ t_cmdlist_item
|
||||
│ │ ╰─ t_pipeline
|
||||
│ │ ├─ num_cmd = 1
|
||||
│ │ ╰─ cmd[0]
|
||||
│ │ ╰─ t_simple_cmd
|
||||
│ │ ├─ words = [echo][hello]
|
||||
│ │ ╰─ t_redir_list
|
||||
│ │ ╰─ redirection[0]
|
||||
│ │ ╰─ t_redirection
|
||||
│ │ ├─ t_redir_type = REDIR_OUTPUT
|
||||
│ │ ╰─ marker = [outfile]
|
||||
│ ╰─ t_operator = END
|
||||
╰─ (no redirections)
|
||||
EOF
|
||||
|
||||
when_run <<EOF "redirections are parsed"
|
||||
echo hello < in hi > out
|
||||
EOF
|
||||
|
|
@ -119,8 +142,51 @@ expecting <<EOF
|
|||
│ │ ╰─ t_redir_list
|
||||
│ │ ├─ redirection[0]
|
||||
│ │ │ ╰─ t_redirection
|
||||
│ │ │ ├─ t_redir_type = REDIR_INPUT
|
||||
│ │ │ ╰─ marker = [in]
|
||||
│ │ ╰─ redirection[1]
|
||||
│ │ ╰─ t_redirection
|
||||
│ │ ├─ t_redir_type = REDIR_OUTPUT
|
||||
│ │ ╰─ marker = [out]
|
||||
│ ╰─ t_operator = END
|
||||
╰─ (no redirections)
|
||||
EOF
|
||||
|
||||
when_run <<EOF "multiple redirections are parsed"
|
||||
echo << HERE_DOC hello>outfile there < infile < infile2 >> append
|
||||
EOF
|
||||
expecting <<EOF
|
||||
╰─ t_cmdgroup
|
||||
├─ t_cmdlist
|
||||
│ ├─ num_cmds = 1
|
||||
│ ╰─ cmd[0]
|
||||
│ ├─ t_cmdlist_item
|
||||
│ │ ╰─ t_pipeline
|
||||
│ │ ├─ num_cmd = 1
|
||||
│ │ ╰─ cmd[0]
|
||||
│ │ ╰─ t_simple_cmd
|
||||
│ │ ├─ words = [echo][hello][there]
|
||||
│ │ ╰─ t_redir_list
|
||||
│ │ ├─ redirection[0]
|
||||
│ │ │ ╰─ t_redirection
|
||||
│ │ │ ├─ t_redir_type = REDIR_HERE_DOC
|
||||
│ │ │ ╰─ marker = [HERE_DOC]
|
||||
│ │ ├─ redirection[1]
|
||||
│ │ │ ╰─ t_redirection
|
||||
│ │ │ ├─ t_redir_type = REDIR_OUTPUT
|
||||
│ │ │ ╰─ marker = [outfile]
|
||||
│ │ ├─ redirection[2]
|
||||
│ │ │ ╰─ t_redirection
|
||||
│ │ │ ├─ t_redir_type = REDIR_INPUT
|
||||
│ │ │ ╰─ marker = [infile]
|
||||
│ │ ├─ redirection[3]
|
||||
│ │ │ ╰─ t_redirection
|
||||
│ │ │ ├─ t_redir_type = REDIR_INPUT
|
||||
│ │ │ ╰─ marker = [infile2]
|
||||
│ │ ╰─ redirection[4]
|
||||
│ │ ╰─ t_redirection
|
||||
│ │ ├─ t_redir_type = REDIR_APPEND
|
||||
│ │ ╰─ marker = [append]
|
||||
│ ╰─ t_operator = END
|
||||
╰─ (no redirections)
|
||||
EOF
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue