From: Lukas Jiriste Date: Thu, 22 Aug 2024 13:24:28 +0000 (+0200) Subject: Fix shenanigans of wildcards with quotes X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=56846479ba4f31baf1802207436a45838ce388c3;p=42%2Fminishell.git Fix shenanigans of wildcards with quotes For example "echo *''" or "echo *'*'" didn't work. --- diff --git a/src/wildcards.c b/src/wildcards.c index d516f9d..f653db6 100644 --- a/src/wildcards.c +++ b/src/wildcards.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/08 10:50:26 by ljiriste #+# #+# */ -/* Updated: 2024/08/22 14:35:25 by ljiriste ### ########.fr */ +/* Updated: 2024/08/22 15:21:35 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,15 +34,16 @@ int add_entry(t_vec *expanded, t_wildcard_info *info) int branch_at_star(t_vec *expanded, t_wildcard_info *info) { const size_t start_size = expanded->size; + t_wildcard_info info_dup; + info_dup = *info; ++info->current_expand_char; if (add_conformant(expanded, info, '\0')) return (1); if (start_size != expanded->size || *info->current_entry_char == '\0') return (0); - --info->current_expand_char; - ++info->current_entry_char; - return (add_conformant(expanded, info, '\0')); + ++info_dup.current_entry_char; + return (add_conformant(expanded, &info_dup, '\0')); } int expand_further(t_vec *expanded, t_wildcard_info info) @@ -91,14 +92,14 @@ int add_conformant(t_vec *expanded, t_wildcard_info *info, char quote) ++info->current_expand_char; return (add_conformant(expanded, info, quote)); } - if ((*info->current_expand_char == '?' && *info->current_entry_char != '\0') + if ((*info->current_expand_char == '?' && *info->current_entry_char != '\0' && (*info->current_entry_char != '.' || info->current_entry_char != info->entry) && !quote) || (*info->current_expand_char == *info->current_entry_char && (*info->current_expand_char != '*' || quote))) { ++info->current_expand_char; ++info->current_entry_char; return (add_conformant(expanded, info, quote)); } - if (*info->current_expand_char == '*' && (*info->current_entry_char != '.' || info->current_entry_char != info->entry)) + if (*info->current_expand_char == '*' && (*info->current_entry_char != '.' || info->current_entry_char != info->entry) && !quote) return (branch_at_star(expanded, info)); return (0); }