From c5e15903e07ce0c60cff81f356ee86c78a7cbad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Fri, 18 Apr 2025 10:11:12 +0200 Subject: [PATCH] fix(builtin/export): show error on invalid identifiers such as % and $ --- src/executing/simple_cmd/builtin_export.c | 21 ++++++++++++--------- test.sh | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/executing/simple_cmd/builtin_export.c b/src/executing/simple_cmd/builtin_export.c index 131100f..ab4efeb 100644 --- a/src/executing/simple_cmd/builtin_export.c +++ b/src/executing/simple_cmd/builtin_export.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/01 14:00:32 by khais #+# #+# */ -/* Updated: 2025/04/18 10:01:59 by khais ### ########.fr */ +/* Updated: 2025/04/18 10:09:09 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,21 +29,24 @@ static void single_export(char *arg, t_minishell *app) char *key; char *value; - if (arg[0] == '\0') - invalid_ident(arg); - if (ft_strchr(arg, '=') != NULL) + key = envp_get_key(arg); + if (is_identifier(key)) { - key = envp_get_key(arg); value = envp_get_val(arg); - if (is_identifier(key) == false) + if (value[0] == '\0' && ft_strchr(arg, '=') == NULL) { - invalid_ident(arg); free2(key, value); - app->last_return_value = 1; + return ; } - else if (env_set_entry(&app->env, key, value) == NULL) + if (env_set_entry(&app->env, key, value) == NULL) ft_perror("minishell: export"); } + else + { + free(key); + invalid_ident(arg); + app->last_return_value = 1; + } } t_builtin_type builtin_export(t_simple_cmd *cmd, t_minishell *app) diff --git a/test.sh b/test.sh index dca722c..685b9c3 100755 --- a/test.sh +++ b/test.sh @@ -749,10 +749,25 @@ EOF when_run <