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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 "../../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)
{
char *key;
char *value;
if (arg[0] == '\0')
invalid_ident(arg);
if (ft_strchr(arg, '=') != NULL)
{
key = envp_get_key(arg);
value = envp_get_val(arg);
if (is_identifier(key) == false)
{
ft_dprintf(STDERR_FILENO,
"minishell: export: `%s': not a valid identifier\n", arg);
invalid_ident(arg);
free2(key, value);
app->last_return_value = 1;
}