Fix shenanigans of wildcards with quotes
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 22 Aug 2024 13:24:28 +0000 (15:24 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 22 Aug 2024 13:27:41 +0000 (15:27 +0200)
For example "echo *''" or "echo *'*'" didn't work.

src/wildcards.c

index d516f9d6904d323d3dd7eb7d53f335196d020668..f653db6af91a30e8bf12e33c054922f294458a55 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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);
 }