fix(builtin/export): empty arguments were not identified as invalid identifiers

This commit is contained in:
Khaïs COLIN 2025-04-18 10:02:26 +02:00
parent 6b2e15d301
commit efaf4708f9
2 changed files with 18 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/01 14:00:32 by khais #+# #+# */ /* Created: 2025/04/01 14:00:32 by khais #+# #+# */
/* Updated: 2025/04/01 15:58:28 by khais ### ########.fr */ /* Updated: 2025/04/18 10:01:59 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,19 +18,26 @@
#include <unistd.h> #include <unistd.h>
#include "../../parser/matchers/identifier.h" #include "../../parser/matchers/identifier.h"
static void invalid_ident(char *ident)
{
ft_dprintf(STDERR_FILENO,
"minishell: export: `%s': not a valid identifier\n", ident);
}
static void single_export(char *arg, t_minishell *app) static void single_export(char *arg, t_minishell *app)
{ {
char *key; char *key;
char *value; char *value;
if (arg[0] == '\0')
invalid_ident(arg);
if (ft_strchr(arg, '=') != NULL) if (ft_strchr(arg, '=') != NULL)
{ {
key = envp_get_key(arg); key = envp_get_key(arg);
value = envp_get_val(arg); value = envp_get_val(arg);
if (is_identifier(key) == false) if (is_identifier(key) == false)
{ {
ft_dprintf(STDERR_FILENO, invalid_ident(arg);
"minishell: export: `%s': not a valid identifier\n", arg);
free2(key, value); free2(key, value);
app->last_return_value = 1; app->last_return_value = 1;
} }

View file

@ -747,4 +747,12 @@ expecting <<EOF
$(env | grep HOME) $(env | grep HOME)
EOF EOF
when_run <<EOF "export with empty arguments"
export "" ""
EOF
expecting <<"EOF"
minishell: export: `': not a valid identifier
minishell: export: `': not a valid identifier
EOF
finalize finalize