wordsplit flags: also set W_HASDOLLAR if dollar is found in double quotes

Fixes #15
This commit is contained in:
Khaïs COLIN 2025-02-24 14:46:16 +01:00
parent d26d883a91
commit 695596fde2
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 16 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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();