From 56846479ba4f31baf1802207436a45838ce388c3 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Thu, 22 Aug 2024 15:24:28 +0200 Subject: [PATCH] Fix shenanigans of wildcards with quotes For example "echo *''" or "echo *'*'" didn't work. --- src/wildcards.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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); } -- 2.30.2