From 2180909285986c9ba90d6790d9683a8fc5ace4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 22 Apr 2025 12:45:28 +0200 Subject: [PATCH] fix(expansion/wildcard): do not remove quotes twice on non-pattern strings There is still an issue with removing too many quotes when expanding variables (see #138). This will be tackled in a later PR. --- src/executing/simple_cmd/simple_cmd_execute.c | 5 ++++- src/subst/subst.h | 7 ++++--- src/subst/wildcard_exp.c | 4 +++- test.sh | 8 ++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/executing/simple_cmd/simple_cmd_execute.c b/src/executing/simple_cmd/simple_cmd_execute.c index 5e7d59b..ec9e0b0 100644 --- a/src/executing/simple_cmd/simple_cmd_execute.c +++ b/src/executing/simple_cmd/simple_cmd_execute.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/27 16:21:56 by khais #+# #+# */ -/* Updated: 2025/04/21 08:45:05 by khais ### ########.fr */ +/* Updated: 2025/04/22 13:14:33 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,13 +43,16 @@ static t_simple_cmd *post_process_command(t_simple_cmd *cmd, t_minishell *app) simple_cmd_post_process_debug(cmd, app); if (simple_cmd_expand_vars(cmd, app) == NULL) return (NULL); + simple_cmd_post_process_debug(cmd, app); if (simple_cmd_fieldsplit(cmd) == NULL) { app->last_return_value = 1; return (NULL); } + simple_cmd_post_process_debug(cmd, app); if (simple_cmd_expand_wildcards(cmd) == NULL) return (NULL); + simple_cmd_post_process_debug(cmd, app); if (simple_cmd_remove_quotes(cmd) == NULL) return (NULL); return (cmd); diff --git a/src/subst/subst.h b/src/subst/subst.h index aeb6ad5..0f129ae 100644 --- a/src/subst/subst.h +++ b/src/subst/subst.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* subst.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/23 15:01:40 by jguelen #+# #+# */ -/* Updated: 2025/03/21 18:47:30 by jguelen ### ########.fr */ +/* Created: 2025/04/22 13:14/27 by khais #+# #+# */ +/* Updated: 2025/04/22 13:14:27 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,5 +43,6 @@ void destroy_pattern_check(char **pattern_check, size_t len); void build_pattern_checks(char *str, t_worddesc *pattern, char **checker); void clean_pattern(t_worddesc *file_pattern); +int ispattern(t_worddesc *desc); #endif diff --git a/src/subst/wildcard_exp.c b/src/subst/wildcard_exp.c index 31d751e..69d2b67 100644 --- a/src/subst/wildcard_exp.c +++ b/src/subst/wildcard_exp.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/20 15:01:38 by jguelen #+# #+# */ -/* Updated: 2025/04/08 16:31:46 by khais ### ########.fr */ +/* Updated: 2025/04/22 13:18:18 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -168,6 +168,8 @@ char fits_pattern(char *str, t_worddesc *pattern) */ t_wordlist *expand_star(t_worddesc *file_pattern) { + if (!ispattern(file_pattern)) + return (NULL); clean_pattern(file_pattern); return (expand_star_core(file_pattern)); } diff --git a/test.sh b/test.sh index 8395d97..5bdb150 100755 --- a/test.sh +++ b/test.sh @@ -928,4 +928,12 @@ expecting <