wordsplit: return error for unclosed quotes

This commit is contained in:
Khaïs COLIN 2025-02-17 14:47:45 +01:00
parent 7806043a98
commit 558ddb4096
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 23 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 17:02:32 by khais #+# #+# */ /* Created: 2025/02/13 17:02:32 by khais #+# #+# */
/* Updated: 2025/02/17 14:20:45 by khais ### ########.fr */ /* Updated: 2025/02/17 14:54:11 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -106,5 +106,7 @@ t_wordlist *minishell_wordsplit(char *original)
break ; break ;
idx++; idx++;
} }
if (quote != '\0')
return (wordlist_destroy(wordlist), NULL);
return (wordlist); return (wordlist);
} }

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 15:17:56 by khais #+# #+# */ /* Created: 2025/02/13 15:17:56 by khais #+# #+# */
/* Updated: 2025/02/17 14:37:17 by khais ### ########.fr */ /* Updated: 2025/02/17 14:55:31 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,7 @@
#include "testutil.h" #include "testutil.h"
#include "libft.h" #include "libft.h"
#include "../src/parser/wordsplit/wordsplit.h" #include "../src/parser/wordsplit/wordsplit.h"
#include "unistd.h"
#include <stdlib.h> #include <stdlib.h>
/* /*
@ -112,6 +113,22 @@ static void test_wordsplit_mixed_broken(void)
wordlist_destroy(words); wordlist_destroy(words);
} }
static void test_wordsplit_unclosed_single(void)
{
t_wordlist *words;
words = minishell_wordsplit("'hello");
assert(words == NULL);
}
static void test_wordsplit_unclosed_double(void)
{
t_wordlist *words;
words = minishell_wordsplit("\"hello");
assert(words == NULL);
}
int main(void) { int main(void) {
test_wordsplit_singleword(); test_wordsplit_singleword();
test_wordsplit_singleword_with_blanks(); test_wordsplit_singleword_with_blanks();
@ -121,5 +138,7 @@ int main(void) {
test_wordsplit_mixed_single_in_double(); test_wordsplit_mixed_single_in_double();
test_wordsplit_mixed_double_in_single(); test_wordsplit_mixed_double_in_single();
test_wordsplit_mixed_broken(); test_wordsplit_mixed_broken();
test_wordsplit_unclosed_single();
test_wordsplit_unclosed_double();
return (0); return (0);
} }