mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix(builtin/export): empty arguments were not identified as invalid identifiers
This commit is contained in:
parent
6b2e15d301
commit
efaf4708f9
2 changed files with 18 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
8
test.sh
8
test.sh
|
|
@ -747,4 +747,12 @@ expecting <<EOF
|
|||
$(env | grep HOME)
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue