mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix(builtin/export): show error on invalid identifiers such as % and $
This commit is contained in:
parent
efaf4708f9
commit
c5e15903e0
2 changed files with 27 additions and 9 deletions
|
|
@ -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/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 *key;
|
||||||
char *value;
|
char *value;
|
||||||
|
|
||||||
if (arg[0] == '\0')
|
key = envp_get_key(arg);
|
||||||
invalid_ident(arg);
|
if (is_identifier(key))
|
||||||
if (ft_strchr(arg, '=') != NULL)
|
|
||||||
{
|
{
|
||||||
key = envp_get_key(arg);
|
|
||||||
value = envp_get_val(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);
|
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");
|
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)
|
t_builtin_type builtin_export(t_simple_cmd *cmd, t_minishell *app)
|
||||||
|
|
|
||||||
15
test.sh
15
test.sh
|
|
@ -749,10 +749,25 @@ EOF
|
||||||
|
|
||||||
when_run <<EOF "export with empty arguments"
|
when_run <<EOF "export with empty arguments"
|
||||||
export "" ""
|
export "" ""
|
||||||
|
echo \$?
|
||||||
EOF
|
EOF
|
||||||
expecting <<"EOF"
|
expecting <<"EOF"
|
||||||
minishell: export: `': not a valid identifier
|
minishell: export: `': not a valid identifier
|
||||||
minishell: export: `': not a valid identifier
|
minishell: export: `': not a valid identifier
|
||||||
|
1
|
||||||
|
EOF
|
||||||
|
|
||||||
|
when_run <<EOF "export with invalid identifiers"
|
||||||
|
export % $ 0 1 \$?
|
||||||
|
echo \$?
|
||||||
|
EOF
|
||||||
|
expecting <<"EOF"
|
||||||
|
minishell: export: `%': not a valid identifier
|
||||||
|
minishell: export: `$': not a valid identifier
|
||||||
|
minishell: export: `0': not a valid identifier
|
||||||
|
minishell: export: `1': not a valid identifier
|
||||||
|
minishell: export: `0': not a valid identifier
|
||||||
|
1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
finalize
|
finalize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue