From 695596fde2b7d2f0687b7b17c3d71a1aa9a3e64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Mon, 24 Feb 2025 14:46:16 +0100 Subject: [PATCH] wordsplit flags: also set W_HASDOLLAR if dollar is found in double quotes Fixes #15 --- src/parser/wordsplit/tokenizing_1_5.c | 4 ++-- tests/word_splitting.c | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/parser/wordsplit/tokenizing_1_5.c b/src/parser/wordsplit/tokenizing_1_5.c index e7d56a6..7473576 100644 --- a/src/parser/wordsplit/tokenizing_1_5.c +++ b/src/parser/wordsplit/tokenizing_1_5.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/19 13:20:01 by jguelen #+# #+# */ -/* Updated: 2025/02/20 14:17:03 by khais ### ########.fr */ +/* Updated: 2025/02/24 14:51:09 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -105,7 +105,7 @@ bool rule_quote(t_token_build *builder, char *original) */ bool rule_var_substitution(t_token_build *builder, char *original) { - if (unquoted(builder) && original[builder->idx] == '$') + if (original[builder->idx] == '$' && builder->quote != '\'') { push_char(builder, original[builder->idx]); builder->cur_flags |= W_HASDOLLAR; diff --git a/tests/word_splitting.c b/tests/word_splitting.c index a74f76b..0ca53f6 100644 --- a/tests/word_splitting.c +++ b/tests/word_splitting.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/13 15:17:56 by khais #+# #+# */ -/* Updated: 2025/02/20 14:22:06 by khais ### ########.fr */ +/* Updated: 2025/02/24 14:49:09 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -187,6 +187,18 @@ static void test_wordsplit_var_substitution(void) wordlist_destroy(words); } +static void test_wordsplit_var_substitution_quotes(void) +{ + t_wordlist *words; + + words = minishell_wordsplit("VAR=\"$VAR\""); + assert(W_HASDOLLAR & wordlist_get(words, 0)->flags); + wordlist_destroy(words); + words = minishell_wordsplit("VAR='$VAR'"); + assert((W_HASDOLLAR & wordlist_get(words, 0)->flags) == 0); + wordlist_destroy(words); +} + static void test_wordsplit_quote_detection_nonnested(void) { t_wordlist *words; @@ -254,6 +266,7 @@ int main(void) { test_wordsplit_all_operators(); test_wordsplit_operator_combining(); test_wordsplit_var_substitution(); + test_wordsplit_var_substitution_quotes(); test_wordsplit_quote_detection_nonnested(); test_wordsplit_quote_detection_nested_double_in_simple(); test_wordsplit_quote_detection_nested_single_in_double();