mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
pipeline parse: detect and reject pipe at start of command
This commit is contained in:
parent
36df14e599
commit
a8711568c1
2 changed files with 14 additions and 2 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/24 14:36:43 by khais #+# #+# */
|
/* Created: 2025/02/24 14:36:43 by khais #+# #+# */
|
||||||
/* Updated: 2025/02/24 15:09:35 by khais ### ########.fr */
|
/* Updated: 2025/02/24 15:21:37 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -77,6 +77,8 @@ static void pipeline_delimit(t_pipeline_builder *builder)
|
||||||
**
|
**
|
||||||
** - Assumes that current word is unset.
|
** - Assumes that current word is unset.
|
||||||
** - Load the next word.
|
** - Load the next word.
|
||||||
|
** - If the current word is a pipe, it means there was a pipe on the start of
|
||||||
|
** the command, which is disalowed. set ft_errno and return NULL.
|
||||||
** - While there are still words remaining in the input stream
|
** - While there are still words remaining in the input stream
|
||||||
** - If we have a pipe character
|
** - If we have a pipe character
|
||||||
** - Delimit the current command
|
** - Delimit the current command
|
||||||
|
|
@ -94,6 +96,8 @@ static void pipeline_delimit(t_pipeline_builder *builder)
|
||||||
t_pipeline *pipeline_parse_wordlist(t_pipeline_builder *builder)
|
t_pipeline *pipeline_parse_wordlist(t_pipeline_builder *builder)
|
||||||
{
|
{
|
||||||
next_word(builder);
|
next_word(builder);
|
||||||
|
if (current_is_pipe(builder))
|
||||||
|
return (builder_destroy(builder), ft_errno(FT_EUNEXPECTED_PIPE), NULL);
|
||||||
while (!eof(builder))
|
while (!eof(builder))
|
||||||
{
|
{
|
||||||
if (current_is_pipe(builder))
|
if (current_is_pipe(builder))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/21 13:13:58 by khais #+# #+# */
|
/* Created: 2025/02/21 13:13:58 by khais #+# #+# */
|
||||||
/* Updated: 2025/02/21 16:03:39 by khais ### ########.fr */
|
/* Updated: 2025/02/24 15:19:39 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -110,6 +110,13 @@ static void test_parse_pipeline_triple_pipe_rejected(void)
|
||||||
assert(ft_errno_get() == FT_EUNEXPECTED_PIPE);
|
assert(ft_errno_get() == FT_EUNEXPECTED_PIPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_parse_pipeline_pipe_at_start_rejected(void)
|
||||||
|
{
|
||||||
|
ft_errno(FT_ESUCCESS);
|
||||||
|
assert(parse_pipeline("| echo hello | tee output.txt") == NULL);
|
||||||
|
assert(ft_errno_get() == FT_EUNEXPECTED_PIPE);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
test_parse_empty_pipeline();
|
test_parse_empty_pipeline();
|
||||||
|
|
@ -119,5 +126,6 @@ int main(void)
|
||||||
test_parse_pipeline_four_cmd();
|
test_parse_pipeline_four_cmd();
|
||||||
test_parse_pipeline_double_pipe_rejected();
|
test_parse_pipeline_double_pipe_rejected();
|
||||||
test_parse_pipeline_triple_pipe_rejected();
|
test_parse_pipeline_triple_pipe_rejected();
|
||||||
|
test_parse_pipeline_pipe_at_start_rejected();
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue