mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
quote removal: handle nested quotes
This commit is contained in:
parent
a3d2143b8b
commit
94e55d1d8b
2 changed files with 25 additions and 3 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/28 13:52:02 by khais #+# #+# */
|
||||
/* Updated: 2025/03/07 11:13:49 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/07 11:20:48 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ t_worddesc *remove_quotes(t_worddesc *word)
|
|||
i = 0;
|
||||
while (word->word[i] != '\0')
|
||||
{
|
||||
if (!is_quote(word->word[i]))
|
||||
if (!is_quote(word->word[i]) || is_quote(word->marker[i]))
|
||||
buf = ft_buffer_pushchar(buf, word->word[i]);
|
||||
i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/28 13:46:56 by khais #+# #+# */
|
||||
/* Updated: 2025/03/07 11:14:48 by khais ### ########.fr */
|
||||
/* Updated: 2025/03/07 11:19:37 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -62,10 +62,32 @@ static void test_quote_removal_double_quotes(void)
|
|||
worddesc_destroy(got_word);
|
||||
}
|
||||
|
||||
static void test_quote_removal_mixed_single_in_double(void)
|
||||
{
|
||||
t_worddesc *word = create_single_word("\"'word'\"");
|
||||
t_worddesc *got_word = remove_quotes(word);
|
||||
assert_strequal("'word'", got_word->word);
|
||||
assert(got_word->marker == NULL);
|
||||
worddesc_destroy(word);
|
||||
worddesc_destroy(got_word);
|
||||
}
|
||||
|
||||
static void test_quote_removal_mixed_double_in_single(void)
|
||||
{
|
||||
t_worddesc *word = create_single_word("'\"word\"'");
|
||||
t_worddesc *got_word = remove_quotes(word);
|
||||
assert_strequal("\"word\"", got_word->word);
|
||||
assert(got_word->marker == NULL);
|
||||
worddesc_destroy(word);
|
||||
worddesc_destroy(got_word);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_quote_removal_no_quotes_single_word();
|
||||
test_quote_removal_null();
|
||||
test_quote_removal_single_quotes();
|
||||
test_quote_removal_double_quotes();
|
||||
test_quote_removal_mixed_single_in_double();
|
||||
test_quote_removal_mixed_double_in_single();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue