From e5952b3f4343a0d32d1c13dbbb853e0e11e0480f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gu=C3=A9len?= Date: Sat, 26 Apr 2025 15:53:34 +0200 Subject: [PATCH] Behaviour seems inconsistent --- src/parser/wordsplit/wordsplit_utils.c | 4 ++-- src/subst/wildcard_exp.c | 7 +++++-- src/subst/wildcard_exp_utils2.c | 23 ++++++++++++++++++++--- test.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/parser/wordsplit/wordsplit_utils.c b/src/parser/wordsplit/wordsplit_utils.c index d0fdeac..093bd44 100644 --- a/src/parser/wordsplit/wordsplit_utils.c +++ b/src/parser/wordsplit/wordsplit_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* wordsplit_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: khais +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/20 14:02:29 by khais #+# #+# */ -/* Updated: 2025/04/09 13:34:02 by khais ### ########.fr */ +/* Updated: 2025/04/26 15:07:17 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/src/subst/wildcard_exp.c b/src/subst/wildcard_exp.c index 062d05b..c92bc4b 100644 --- a/src/subst/wildcard_exp.c +++ b/src/subst/wildcard_exp.c @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/20 15:01:38 by jguelen #+# #+# */ -/* Updated: 2025/04/25 18:54:06 by jguelen ### ########.fr */ +/* Updated: 2025/04/26 15:18:35 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -173,5 +173,8 @@ t_wordlist *expand_star(t_worddesc *file_pattern) clean_pattern(pattern_copy); expanded = expand_star_core(pattern_copy); worddesc_destroy(pattern_copy); - return (expanded); + if (ft_strcmp(expanded->word->word, file_pattern->word)) + return (expanded); + wordlist_destroy(expanded); + return (NULL); } diff --git a/src/subst/wildcard_exp_utils2.c b/src/subst/wildcard_exp_utils2.c index 4056960..375af21 100644 --- a/src/subst/wildcard_exp_utils2.c +++ b/src/subst/wildcard_exp_utils2.c @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/15 15:09:56 by jguelen #+# #+# */ -/* Updated: 2025/04/25 18:53:04 by jguelen ### ########.fr */ +/* Updated: 2025/04/26 15:06:41 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,6 +66,15 @@ int ispattern(t_worddesc *desc) return (0); } +static char pattern_marker_quote_flip(char c, char *quote) +{ + if (*quote == c) + *quote = '\0'; + else if (*quote == '\0') + *quote = c; + return (*quote); +} + t_worddesc *deal_with_potential_pattern_marker(t_worddesc *file_pattern) { t_worddesc *pattern_copy; @@ -73,14 +82,22 @@ t_worddesc *deal_with_potential_pattern_marker(t_worddesc *file_pattern) char quote; pattern_copy = worddesc_copy(file_pattern); + if (!pattern_copy) + return (NULL); if (file_pattern->flags & W_HASDOLLAR) { i = 0; quote = '\0'; - while (file_pattern->word[i]) + while (pattern_copy->word[i]) { + if (quote == '\0' || pattern_copy->word[i] == quote) + pattern_copy->marker[i] = ' '; + else + pattern_copy->marker[i] = quote; + if (pattern_copy->word[i] == '\'' || pattern_copy->word[i] == '"') + pattern_marker_quote_flip(pattern_copy->word[i], "e); i++; } } return (pattern_copy); -} \ No newline at end of file +} diff --git a/test.sh b/test.sh index 8973653..1d75faf 100755 --- a/test.sh +++ b/test.sh @@ -1330,6 +1330,32 @@ expecting <